mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: use readline to readFileByLine (50% faster)
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import { bench, group, run } from 'mitata';
|
||||
import { processLine, processLineFromReadline } from './process-line';
|
||||
import { readFileByLine } from './fetch-text-by-line';
|
||||
import { readFileByLine, readFileByLineLegacy } from './fetch-text-by-line';
|
||||
import path from 'node:path';
|
||||
import fsp from 'node:fs/promises';
|
||||
import { SOURCE_DIR } from '../constants/dir';
|
||||
|
||||
const file = path.join(SOURCE_DIR, 'domainset/cdn.conf');
|
||||
|
||||
group(() => {
|
||||
bench('readFileByLine', () => processLineFromReadline(readFileByLine(file)));
|
||||
bench('fsp.readFile', () => fsp.readFile(file, 'utf-8').then((content) => content.split('\n').filter(processLine)));
|
||||
});
|
||||
(async () => {
|
||||
const { bench, group, run } = await import('mitata');
|
||||
|
||||
run();
|
||||
group(() => {
|
||||
bench('readFileByLine', () => processLineFromReadline(readFileByLine(file)));
|
||||
bench('readFileByLineLegacy', () => processLineFromReadline(readFileByLineLegacy(file)));
|
||||
bench('fsp.readFile', () => fsp.readFile(file, 'utf-8').then((content) => content.split('\n').filter(processLine)));
|
||||
});
|
||||
|
||||
run();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user