Performance impact of contracts
JavaScript performance comparison
Info
Performance impact of Contracts.coffee (http://disnetdev.com/contracts.coffee/). You'll need Firefox 5 / 6 / 7+ to test performance, because only firefox currently supports ES5 proxies.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="//disnetdev.com/contracts.coffee/lib/loadContracts.js"></script>
<script src="//disnetdev.com/contracts.coffee/extras/coffee-script.js"></script>
<script>
var id;
id = guard(fun([Num], Num, {}),function(x) {
return x;
});
var tests = {
id: function(x) {return x;},
optional: function(n, s, b) {
return b ? n : s;
},
list: [42, "foo", [true, 24]],
object: {
a: "foo",
b: 42,
f: function(x) {return x;},
},
};
var testsc = {
id: guard(fun([Num], Num, {}), function(x) {
return x;
}).use(),
optional: guard(fun([Num, Str, opt(Bool)], Num, {}), function(n, s, b) {
return b ? n : s;
}).use(),
list: guard(arr([Num, Str, arr([Bool, Num])]), [42, "foo", [true, 24]]).use(),
object: guard(object({
a: Str,
b: Num,
f: fun([Num], Num, {})
}, {}),{
a: "foo",
b: 42,
f: function(x) {
return x;
}
}).use(),
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
1 arg, no contracts |
|
pending… |
1 arg, contracts |
|
pending… |
optional, no contracts |
|
pending… |
optional, contracts |
|
pending… |
array, no contracts |
|
pending… |
array, contracts |
|
pending… |
object, no contracts |
|
pending… |
object, contracts |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 2: published by paul
- Revision 3: published by paul
- Revision 4: published by Paul Miller
0 comments