Skip to content

Commit 88bbc88

Browse files
committed
adding some benchmarking and perf tweaks
1 parent 13a9a5e commit 88bbc88

File tree

8 files changed

+697
-29
lines changed

8 files changed

+697
-29
lines changed

Gruntfile.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = function(grunt) {
1111
grunt.loadNpmTasks('grunt-sweet.js');
1212
grunt.loadNpmTasks('grunt-mocha-test');
1313
grunt.loadNpmTasks('grunt-template');
14+
grunt.loadNpmTasks('grunt-benchmark');
1415

1516

1617
// Project configuration.
@@ -32,6 +33,14 @@ module.exports = function(grunt) {
3233
},
3334
src: "test/test_contracts.js",
3435
dest: "build/tests/test_contracts.js"
36+
},
37+
benchmark: {
38+
options: {
39+
readableNames: true,
40+
modules: ["./macros/index.js"]
41+
},
42+
src: "benchmark/contracts-vs-rho.js",
43+
dest: "benchmark/cvr-benchmark.js"
3544
}
3645
},
3746
template: {
@@ -90,6 +99,12 @@ module.exports = function(grunt) {
9099
src: ['contracts.js', 'test/**/*.js']
91100
}
92101
},
102+
benchmark: {
103+
all: {
104+
src: ["benchmark/cvr-benchmark.js"],
105+
dest: "benchmark/results.csv"
106+
}
107+
},
93108
pandoc: {
94109
options: {
95110
pandocOptions: ["--to=html5",
@@ -141,6 +156,8 @@ module.exports = function(grunt) {
141156
// Default task.
142157
grunt.registerTask('default', ["sweetjs:contracts", "template", "copy", "sweetjs:tests", "mochaTest"]);
143158

159+
grunt.registerTask("bench", ["sweetjs:benchmark", "benchmark"]);
160+
144161
grunt.registerTask("docs", ["pandoc"]);
145162

146163
};

benchmark/contracts-vs-rho.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import @ from "contracts.js"
2+
var c = require('rho-contracts');
3+
4+
function baseId(x) { return x; }
5+
6+
@ (Num) -> Num
7+
function id(x) { return x; }
8+
9+
var rhoId = c.fun({
10+
x: c.number
11+
}).returns(c.number).wrap(function(x) { return x; });
12+
13+
module.exports = {
14+
name: "contracts.js vs rho-contracts",
15+
tests: {
16+
// 'Id no contracts': function() {
17+
// baseId(100);
18+
// },
19+
'Id contracts.js': function() {
20+
id(100);
21+
},
22+
'Id rho-contracts': function() {
23+
rhoId(100);
24+
}
25+
}
26+
};

benchmark/cvr-benchmark.js

Lines changed: 566 additions & 0 deletions
Large diffs are not rendered by default.

benchmark/results.csv

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name,date,error,count,cycles,hz
2+
"contracts-vs-rho","Wed Aug 06 2014 20:15:41 GMT-0700 (PDT)",,50652,3,957152.4301783083
3+
"Id contracts.js","Wed Aug 06 2014 20:22:44 GMT-0700 (PDT)",,1352,5,20766.364028439533
4+
"Id rho-contracts","Wed Aug 06 2014 20:22:44 GMT-0700 (PDT)",Error: The test "Id rho-contracts" is empty. This may be the result of dead code removal.,0,0,0
5+
"Id contracts.js","Wed Aug 06 2014 20:28:14 GMT-0700 (PDT)",,1447,5,22340.81283179879
6+
"Id rho-contracts","Wed Aug 06 2014 20:28:19 GMT-0700 (PDT)",,4467,4,69795.03317332706
7+
"Id contracts.js","Wed Aug 06 2014 20:28:53 GMT-0700 (PDT)",,1363,7,20888.765159468992
8+
"Id rho-contracts","Wed Aug 06 2014 20:28:53 GMT-0700 (PDT)",ReferenceError: rhoId is not defined,0,0,0
9+
"Id contracts.js","Wed Aug 06 2014 20:29:26 GMT-0700 (PDT)",,1336,5,20808.23673446918
10+
"Id rho-contracts","Wed Aug 06 2014 20:29:26 GMT-0700 (PDT)",ReferenceError: rhoId is not defined,0,0,0
11+
"Id contracts.js","Wed Aug 06 2014 20:29:39 GMT-0700 (PDT)",,1400,6,21922.730884277065
12+
"Id rho-contracts","Wed Aug 06 2014 20:29:39 GMT-0700 (PDT)",ReferenceError: rhoId is not defined,0,0,0
13+
"Id contracts.js","Wed Aug 06 2014 20:31:51 GMT-0700 (PDT)",,1348,6,20852.009537377173
14+
"Id rho-contracts","Wed Aug 06 2014 20:31:56 GMT-0700 (PDT)",,4705,5,70208.85239618989
15+
"Id contracts.js","Wed Aug 06 2014 20:37:38 GMT-0700 (PDT)",,28721,7,548522.5326938939
16+
"Id rho-contracts","Wed Aug 06 2014 20:37:43 GMT-0700 (PDT)",,4287,4,68033.87293886884
17+
"Id no contracts","Wed Aug 06 2014 20:53:13 GMT-0700 (PDT)",,4439077,7,77137010.0335377
18+
"Id contracts.js","Wed Aug 06 2014 20:53:18 GMT-0700 (PDT)",,1476,5,21935.77821649957
19+
"Id rho-contracts","Wed Aug 06 2014 20:53:24 GMT-0700 (PDT)",,4573,4,70873.04015608411
20+
"Id contracts.js","Thu Aug 07 2014 00:15:09 GMT-0700 (PDT)",,1448,4,20760.91598643842
21+
"Id rho-contracts","Thu Aug 07 2014 00:15:14 GMT-0700 (PDT)",,4450,4,70486.0941749407
22+
"Id contracts.js","Thu Aug 07 2014 00:53:13 GMT-0700 (PDT)",,714,6,13179.320171236248
23+
"Id rho-contracts","Thu Aug 07 2014 00:53:19 GMT-0700 (PDT)",,4504,5,71882.0058785958
24+
"Id contracts.js","Thu Aug 07 2014 00:53:40 GMT-0700 (PDT)",,711,4,12946.317168419162
25+
"Id rho-contracts","Thu Aug 07 2014 00:53:45 GMT-0700 (PDT)",,4167,4,66965.03219938242
26+
"Id contracts.js","Thu Aug 07 2014 00:55:50 GMT-0700 (PDT)",,1482,5,22706.17674748339
27+
"Id rho-contracts","Thu Aug 07 2014 00:55:55 GMT-0700 (PDT)",,4423,7,66668.28293579744
28+
"Id contracts.js","Thu Aug 07 2014 00:59:52 GMT-0700 (PDT)",,947,5,15946.538442668669
29+
"Id rho-contracts","Thu Aug 07 2014 00:59:58 GMT-0700 (PDT)",,4218,4,66309.4408432277
30+
"Id contracts.js","Thu Aug 07 2014 01:01:26 GMT-0700 (PDT)",,4576,3,55392.94956440377
31+
"Id rho-contracts","Thu Aug 07 2014 01:01:31 GMT-0700 (PDT)",,4438,4,68676.16571062598
32+
"Id contracts.js","Thu Aug 07 2014 01:14:54 GMT-0700 (PDT)",,600,4,10696.613886165926
33+
"Id rho-contracts","Thu Aug 07 2014 01:15:00 GMT-0700 (PDT)",,4438,7,59433.29052258584
34+
"Id contracts.js","Thu Aug 07 2014 01:15:28 GMT-0700 (PDT)",,605,6,11216.670442965618
35+
"Id rho-contracts","Thu Aug 07 2014 01:15:33 GMT-0700 (PDT)",,4048,6,63029.457873145635
36+
"Id contracts.js","Thu Aug 07 2014 01:15:50 GMT-0700 (PDT)",,604,8,9895.314633862055
37+
"Id rho-contracts","Thu Aug 07 2014 01:15:56 GMT-0700 (PDT)",,4244,4,62805.99890718948
38+
"Id contracts.js","Thu Aug 07 2014 01:33:05 GMT-0700 (PDT)",,1387,5,21122.45270261521
39+
"Id rho-contracts","Thu Aug 07 2014 01:33:11 GMT-0700 (PDT)",,4454,5,69723.99116955888
40+
"Id contracts.js","Thu Aug 07 2014 01:38:45 GMT-0700 (PDT)",,24139,6,465383.89464260184
41+
"Id rho-contracts","Thu Aug 07 2014 01:38:51 GMT-0700 (PDT)",,4635,5,71571.25025269778
42+
"Id contracts.js","Thu Aug 07 2014 01:39:57 GMT-0700 (PDT)",,22988,7,436943.0191639323
43+
"Id rho-contracts","Thu Aug 07 2014 01:40:02 GMT-0700 (PDT)",,4442,4,64199.60191626977
44+
"Id contracts.js","Thu Aug 07 2014 01:43:43 GMT-0700 (PDT)",,678,6,12520.052673558943
45+
"Id rho-contracts","Thu Aug 07 2014 01:43:48 GMT-0700 (PDT)",,4355,4,70550.43777815324
46+
"Id contracts.js","Thu Aug 07 2014 01:44:06 GMT-0700 (PDT)",,637,4,11814.581994111255
47+
"Id rho-contracts","Thu Aug 07 2014 01:44:12 GMT-0700 (PDT)",,4274,4,68026.3213069852
48+
"Id contracts.js","Thu Aug 07 2014 01:45:06 GMT-0700 (PDT)",,721,4,13105.843239853413
49+
"Id rho-contracts","Thu Aug 07 2014 01:45:12 GMT-0700 (PDT)",,4321,4,68627.46302475703
50+
"Id contracts.js","Thu Aug 07 2014 01:45:42 GMT-0700 (PDT)",,23853,6,445030.34816416464
51+
"Id rho-contracts","Thu Aug 07 2014 01:45:47 GMT-0700 (PDT)",,4049,6,66089.0389700134
52+
"Id contracts.js","Thu Aug 07 2014 01:46:24 GMT-0700 (PDT)",,24082,5,459930.5021380374
53+
"Id rho-contracts","Thu Aug 07 2014 01:46:29 GMT-0700 (PDT)",,4540,7,72270.63488701299
54+
"Id contracts.js","Thu Aug 07 2014 01:47:10 GMT-0700 (PDT)",,709,6,13002.682843312072
55+
"Id rho-contracts","Thu Aug 07 2014 01:47:16 GMT-0700 (PDT)",,4429,6,70976.53042003908
56+
"Id contracts.js","Thu Aug 07 2014 01:47:41 GMT-0700 (PDT)",,22933,4,417809.43645649374
57+
"Id rho-contracts","Thu Aug 07 2014 01:47:46 GMT-0700 (PDT)",,4545,4,65873.85675206262
58+
"Id contracts.js","Thu Aug 07 2014 01:48:06 GMT-0700 (PDT)",,23355,5,433430.3778835461
59+
"Id rho-contracts","Thu Aug 07 2014 01:48:12 GMT-0700 (PDT)",,4182,6,64886.631744746206
60+
"Id contracts.js","Thu Aug 07 2014 01:55:56 GMT-0700 (PDT)",,23481,4,436227.525723691
61+
"Id rho-contracts","Thu Aug 07 2014 01:56:02 GMT-0700 (PDT)",,4422,6,67905.64320426945

macros/disabled.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ let import = macro {
1212
var Blame = {
1313
create: function (name, pos, neg, lineNumber) {
1414
var o = new BlameObj(name, pos, neg, lineNumber);
15-
Object.freeze(o);
15+
// Object.freeze(o);
1616
return o;
1717
},
1818
clone: function (old, props) {
19-
var propsObj = {};
20-
for (var prop in props) {
21-
if (props.hasOwnProperty(prop)) {
22-
propsObj[prop] = { value: props[prop] };
23-
}
24-
}
25-
var o = Object.create(old, propsObj);
26-
Object.freeze(o);
19+
var o = new BlameObj(typeof props.name !== 'undefined' ? props.name : old.name, typeof props.pos !== 'undefined' ? props.pos : old.pos, typeof props.neg !== 'undefined' ? props.neg : old.neg, typeof props.lineNuber !== 'undefined' ? props.lineNuber : old.lineNumber);
20+
o.expected = typeof props.expected !== 'undefined' ? props.expected : old.expected;
21+
o.given = typeof props.given !== 'undefined' ? props.given : old.given;
22+
o.loc = typeof props.loc !== 'undefined' ? props.loc : old.loc;
23+
o.parents = typeof props.parents !== 'undefined' ? props.parents : old.parents;
24+
// Object.freeze(o);
2725
return o;
2826
}
2927
};

macros/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ let import = macro {
1212
var Blame = {
1313
create: function (name, pos, neg, lineNumber) {
1414
var o = new BlameObj(name, pos, neg, lineNumber);
15-
Object.freeze(o);
15+
// Object.freeze(o);
1616
return o;
1717
},
1818
clone: function (old, props) {
19-
var propsObj = {};
20-
for (var prop in props) {
21-
if (props.hasOwnProperty(prop)) {
22-
propsObj[prop] = { value: props[prop] };
23-
}
24-
}
25-
var o = Object.create(old, propsObj);
26-
Object.freeze(o);
19+
var o = new BlameObj(typeof props.name !== 'undefined' ? props.name : old.name, typeof props.pos !== 'undefined' ? props.pos : old.pos, typeof props.neg !== 'undefined' ? props.neg : old.neg, typeof props.lineNuber !== 'undefined' ? props.lineNuber : old.lineNumber);
20+
o.expected = typeof props.expected !== 'undefined' ? props.expected : old.expected;
21+
o.given = typeof props.given !== 'undefined' ? props.given : old.given;
22+
o.loc = typeof props.loc !== 'undefined' ? props.loc : old.loc;
23+
o.parents = typeof props.parents !== 'undefined' ? props.parents : old.parents;
24+
// Object.freeze(o);
2725
return o;
2826
}
2927
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"devDependencies": {
3131
"es6-macros": "0.0.7",
3232
"expect.js": "^0.3.1",
33+
"grunt-benchmark": "^0.3.0",
3334
"grunt-cli": "0.1.x",
3435
"grunt-contrib-copy": "0.4.x",
3536
"grunt-contrib-jshint": "0.7.x",
@@ -40,8 +41,9 @@
4041
"grunt-template": "^0.2.3",
4142
"harmony-reflect": "^1.0.0",
4243
"mocha": "^1.20.1",
43-
"sparkler": "^0.3.3",
44-
"should": "^4.0.4"
44+
"rho-contracts": "0.0.5",
45+
"should": "^4.0.4",
46+
"sparkler": "^0.3.3"
4547
},
4648
"repository": {
4749
"type": "git",

src/contracts.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
// importing patches Proxy to be in line with the new direct proxies
55
require("harmony-reflect");
66
}
7+
operator (|?|) 4 left {$l, $r} => #{ typeof $l !== 'undefined' ? $l : $r }
78

89
var unproxy = new WeakMap();
910
var typeVarMap = new WeakMap();
1011

1112
var Blame = {
1213
create: function(name, pos, neg, lineNumber) {
1314
var o = new BlameObj(name, pos, neg, lineNumber);
14-
Object.freeze(o);
1515
return o;
1616
},
1717
clone: function(old, props) {
18-
var propsObj = {};
19-
for (var prop in props) {
20-
if (props.hasOwnProperty(prop)) {
21-
propsObj[prop] = { value: props[prop] };
22-
}
23-
}
24-
var o = Object.create(old, propsObj);
25-
Object.freeze(o);
18+
var o = new BlameObj(props.name |?| old.name,
19+
props.pos |?| old.pos,
20+
props.neg |?| old.neg,
21+
props.lineNuber |?| old.lineNumber);
22+
o.expected = props.expected |?| old.expected;
23+
o.given = props.given |?| old.given;
24+
o.loc = props.loc |?| old.loc;
25+
o.parents = props.parents |?| old.parents;
2626
return o;
2727
}
2828
};

0 commit comments

Comments
 (0)