Skip to content

Commit

Permalink
Add benchmark script for measuring performance
Browse files Browse the repository at this point in the history
This makes it easier to optimize performance in the future.

See #167
  • Loading branch information
maoberlehner committed May 1, 2018
1 parent e6a5071 commit 280e3c1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ Thumbs.db
coverage
dist
node_modules
!scripts/files/node_modules
!test/bugfix/*/files/node_modules
!test/files/node_modules
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"watch": "lerna run watch",
"build": "lerna run build",
"clean": "lerna run clean",
"benchmark": "node scripts/benchmark.js",
"lint": "tslint **/*.ts -e **/node_modules/** -e **/dist/**",
"coverage": "jest --coverage --maxWorkers=4",
"coveralls": "npm run coverage && cat coverage/lcov.info | coveralls",
Expand Down
22 changes: 22 additions & 0 deletions scripts/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
const { performance } = require(`perf_hooks`);
const path = require(`path`);
const sass = require(`node-sass`);

const magicImporter = require(`../packages/node-sass-magic-importer/dist/index`);

const start = performance.now();

for (let i = 0; i < 100; i += 1) {
sass.renderSync({
file: `scripts/files/benchmark.scss`,
importer: magicImporter({
cwd: path.resolve(__dirname, `files`),
}),
}).css.toString();
}

const end = performance.now();
const duration = end - start;

console.log(`Duration: ${duration}ms`)
5 changes: 5 additions & 0 deletions scripts/files/benchmark.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import '~test-package1';
@import '~test-package2/**/*.scss';
@import '{ .partial-1-1 as .replaced1 } from partials/_partial*';
@import '{ .partial-1-2 as .replaced2 } from partials/_partial*';
@import '{ .partial-1-3 as .replaced3 } from partials/_partial*';
4 changes: 4 additions & 0 deletions scripts/files/node_modules/test-package1/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions scripts/files/node_modules/test-package1/scss/main.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scripts/files/node_modules/test-package2/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions scripts/files/node_modules/test-package2/scss/main.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/files/partials/_partial-1.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.partial-1-1 {
content: 'Partial 1-1';
}

.partial-1-2 {
content: 'Partial 1-2';
}

.partial-1-3 {
content: 'Partial 1-3';
}

0 comments on commit 280e3c1

Please sign in to comment.