Skip to content

Instantly share code, notes, and snippets.

@fabiospampinato
Created December 9, 2023 18:25
Show Gist options
  • Save fabiospampinato/ddd48a1da06bc7c366bbb9c918b57576 to your computer and use it in GitHub Desktop.
Save fabiospampinato/ddd48a1da06bc7c366bbb9c918b57576 to your computer and use it in GitHub Desktop.
dot ignore bench
/* IMPORT */
import benchmark from 'benchloop';
import fs from 'node:fs';
import path from 'node:path';
import toIgnore from 'fast-ignore';
import dotignore from 'dotignore';
/* HELPERS */
const rootPath = path.resolve ( 'tasks/babel' );
const gitignorePath = path.join ( rootPath, '.gitignore' );
const gitignoreContent = fs.readFileSync ( gitignorePath, 'utf8' );
const prettierignorePath = path.join ( rootPath, '.prettierignore' );
const prettierignoreContent = fs.readFileSync ( prettierignorePath, 'utf8' );
const comboContent = gitignoreContent + '\n' + prettierignoreContent;
const filesPaths = fs.readdirSync ( rootPath, { recursive: true } ).sort ();
/* MAIN */
benchmark.config ({
iterations: 10
});
benchmark.group ( 'dotignore', () => {
benchmark ({
name: '.gitignore',
fn: () => {
const _ignore = dotignore.createMatcher ( gitignoreContent );
const ignore = _ignore.shouldIgnore.bind ( _ignore );
filesPaths.forEach ( ignore );
}
});
benchmark ({
name: '.prettierignore',
fn: () => {
const _ignore = dotignore.createMatcher ( prettierignoreContent );
const ignore = _ignore.shouldIgnore.bind ( _ignore );
filesPaths.forEach ( ignore );
}
});
benchmark ({
name: '.gitignore + .prettierignore (individual)',
fn: () => {
const _ignore1 = dotignore.createMatcher ( gitignoreContent );
const _ignore2 = dotignore.createMatcher ( prettierignoreContent );
const ignore1 = _ignore1.shouldIgnore.bind ( _ignore1 );
const ignore2 = _ignore2.shouldIgnore.bind ( _ignore2 );
filesPaths.forEach ( ignore1 );
filesPaths.forEach ( ignore2 );
}
});
benchmark ({
name: '.gitignore + .prettierignore (concat)',
fn: () => {
const _ignore = dotignore.createMatcher ( comboContent );
const ignore = _ignore.shouldIgnore.bind ( _ignore );
filesPaths.forEach ( ignore );
}
});
});
benchmark.group ( 'fast-ignore', () => {
benchmark ({
name: '.gitignore',
fn: () => {
const ignore = toIgnore ( gitignoreContent );
filesPaths.forEach ( ignore );
}
});
benchmark ({
name: '.prettierignore',
fn: () => {
const ignore = toIgnore ( prettierignoreContent );
filesPaths.forEach ( ignore );
}
});
benchmark ({
name: '.gitignore + .prettierignore (individual)',
fn: () => {
const ignore1 = toIgnore ( gitignoreContent );
const ignore2 = toIgnore ( prettierignoreContent );
filesPaths.forEach ( ignore1 );
filesPaths.forEach ( ignore2 );
}
});
benchmark ({
name: '.gitignore + .prettierignore (concat)',
fn: () => {
const ignore = toIgnore ( comboContent );
filesPaths.forEach ( ignore );
}
});
benchmark ({
name: '.gitignore + .prettierignore (combo)',
fn: () => {
const ignore = toIgnore ([ gitignoreContent, prettierignoreContent ]);
filesPaths.forEach ( ignore );
}
});
});
// benchmark.summary ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment