Created
March 20, 2015 18:43
-
-
Save springmeyer/a67d8d77057d30fc4bbe to your computer and use it in GitHub Desktop.
benchmark.js example: testing an async function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great!