-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbenchmark6.js
executable file
·116 lines (104 loc) · 3.11 KB
/
benchmark6.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/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));
}
interp.registerCommand('nop', function(){
return nothing;
});
interp.registerCommand('nop_tclresult', function(){
return TclOk;
});
interp.registerCommand('nop_literal', function(){
return '';
});
interp.registerCommand('nop_async', function(c){
return c(nothing);
});
interp.registerCommand('nop_checkargs', function(args){
interp.checkArgs(args, 0, '');
return nothing;
});
cmd1 = new StringObj('nop');
cmd2 = new StringObj('nop_checkargs');
cmd3 = new StringObj('nop_async');
cmd4 = new StringObj('nop_tclresult');
cmd5 = new StringObj('nop_literal');
v1 = new StringObj('value');
suite.add('nop command', function(){
interp.TclEval(cmd1, function(){});
}, {onComplete: report});
suite.add('nop_tclresult command', function(){
interp.TclEval(cmd4, function(){});
}, {onComplete: report});
suite.add('nop_async command', function(){
interp.TclEval(cmd3, function(){});
}, {onComplete: report});
suite.add('nop_literal command', function(){
interp.TclEval(cmd5, function(){});
}, {onComplete: report});
suite.add('nop_checkargs command', function(){
interp.TclEval(cmd1, function(){});
}, {onComplete: report});
/*
suite.add('direct set_scalar literal', function(){
interp.set_scalar('a', 'b');
}, {onComplete: report});
suite.add('direct set_scalar obj', function(){
interp.set_scalar('a', v1);
}, {onComplete: report});
suite.add('direct set_var (scalar) obj', function(){
interp.set_var('a', v1);
}, {onComplete: report});
suite.add('direct set_var (array) obj', function(){
interp.set_var('arr(b)', v1);
}, {onComplete: report});
suite.add('new StringObj', function(){
return new StringObj('hello, world');
}, {onComplete: report});
suite.add('AsObj', function(){
return tclobj.AsObj('hello, world');
}, {onComplete: report});
*/
suite.add('Construct TclResult', function(){
return new interp.TclResult(types.OK, nothing);
}, {onComplete: report});
suite.add('Construct TclResult, ""', function(){
return new interp.TclResult(types.OK, '');
}, {onComplete: report});
suite.add('Construct TclResult, "foo"', function(){
return new interp.TclResult(types.OK, 'foo');
}, {onComplete: report});
suite.run();
});