Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created March 20, 2015 18:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save springmeyer/a67d8d77057d30fc4bbe to your computer and use it in GitHub Desktop.
Save springmeyer/a67d8d77057d30fc4bbe to your computer and use it in GitHub Desktop.
benchmark.js example: testing an async function
'use strict';
var path = require('path');
var fontnik = require('../');
var Benchmark = require('benchmark');
var opensans = path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf');
var suite = new Benchmark.Suite();
suite
.add('fontnik.load', {
'defer': true,
'fn': function(deferred) {
// avoid test inlining
suite.name;
fontnik.load(opensans,function(err) {
if (err) throw err;
deferred.resolve();
});
}
})
.add('fontnik.range', {
'defer': true,
'fn': function(deferred) {
// avoid test inlining
suite.name;
fontnik.range(opensans,0,256,function(err) {
if (err) throw err;
deferred.resolve();
});
}
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.run({async:true});
@lanjin
Copy link

lanjin commented Apr 15, 2019

great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment