Permalink
Browse files

update the benchmark.js to use the new native strtoul

  • Loading branch information...
1 parent 3db3eeb commit e51321241e647562745b69702d899937dd1d0eb0 @TooTallNate TooTallNate committed May 12, 2012
Showing with 12 additions and 17 deletions.
  1. +12 −17 doc/benchmark.js
View
@@ -5,8 +5,8 @@ var util = require('util')
function measureIterationsOverTime(what, duration, f, granularity) {
granularity = granularity || 1000
- var iterations = 0,
- start = Date.now()
+ var iterations = 0
+ var start = Date.now()
while (Date.now() < (start + duration)) {
for (var i = 0; i < granularity; i++) {
@@ -18,29 +18,24 @@ function measureIterationsOverTime(what, duration, f, granularity) {
var duration = Date.now() - start
var persec = (iterations / (Date.now() - start)) * 1000
- util.log("Executed " + what + " " + iterations + " times in " + duration + "ms " + "(" + persec + "/sec)")
+ util.log('Executed ' + what + ' ' + iterations + ' times in '
+ + duration + 'ms ' + '(' + persec + '/sec)')
}
var benchLibrary = new ffi.Library(null, {
- "abs": [ "int", [ "int" ] ],
- "strtoul": [ "ulong", [ "string", "pointer", "int" ] ]
+ 'strtoul': [ 'ulong', [ 'string', 'pointer', 'int' ] ]
})
-var blabs = benchLibrary.abs
+var string = '1234567890'
+var strtoulPtr = ref.NULL
+var strtoulFunc = require('../test/build/Release/ffi_tests').strtoul
var blstrtoul = benchLibrary.strtoul
-/*measureIterationsOverTime("ffi abs", 5000, function() {
- blabs(1234)
-})*/
-
-measureIterationsOverTime("ffi strtoul", 5000, function() {
- blstrtoul("1234567890", null, 0)
+measureIterationsOverTime('Binding strtoul', 5000, function() {
+ strtoulFunc(string, strtoulPtr, 0)
})
-strtoulFunc = ffi.Bindings.strtoul
-strtoulPtr = ref.NULL
-
-measureIterationsOverTime("Binding strtoul", 5000, function() {
- strtoulFunc("1234567890", strtoulPtr, 0)
+measureIterationsOverTime('ffi strtoul', 5000, function() {
+ blstrtoul(string, strtoulPtr, 0)
})

0 comments on commit e513212

Please sign in to comment.