-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbenchmark7.js
executable file
·69 lines (58 loc) · 1.82 KB
/
benchmark7.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
/*jslint white: true, sloppy: true, plusplus: true */
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite('tcl', {});
var requirejs = require('requirejs');
requirejs.config({
baseUrl: '/Users/cyan/git/js',
paths: {
tcl: 'tcl/amd',
sop: 'tcl/amd',
cfcrypto: 'crypto/src/amd',
webtoolkit: '3rd_party/webtoolkit',
ds: 'datasource/amd',
cflib: 'cflib/amd'
},
nodeRequire: require
});
requirejs([
'tcl/interp',
'tcl/types',
'tcl/objtype_string',
'tcl/tclobject',
'webtoolkit/sprintf'
], function(
TclInterp,
types,
StringObj,
tclobj,
sprintf
){
var interp = new TclInterp(), nothing = new StringObj(''), cmd1, cmd2, v1,
TclOk = new interp.TclResult(types.OK, nothing);
function report(result){
var usec = 1000000.0/result.currentTarget.hz;
console.log(sprintf('%27s: %15.5f / sec ± %f, usec/it: %.4f', result.currentTarget.name, result.currentTarget.hz, result.currentTarget.stats.deviation, usec));
}
cmd1 = new StringObj('string length "hello, world"');
cmd2 = new StringObj('string map {foo FOO bar bAR b *b*} "hello foo bar world baz"');
cmd3 = new StringObj('string trim " hello, world\n\t "');
cmd4 = new StringObj('string trim "/hello, world||" /|');
cmd5 = new StringObj('string match {*[ax]lo? *} "hello, world"');
suite.add('string length', function(){
interp.TclEval(cmd1, function(){});
}, {onComplete: report});
suite.add('string map', function(){
interp.TclEval(cmd2, function(){});
}, {onComplete: report});
suite.add('string trim', function(){
interp.TclEval(cmd3, function(){});
}, {onComplete: report});
suite.add('string trim specific chars', function(){
interp.TclEval(cmd4, function(){});
}, {onComplete: report});
suite.add('string match', function(){
interp.TclEval(cmd5, function(){});
}, {onComplete: report});
suite.run();
});