calculations after boxing numbers inside an object
JavaScript performance comparison
Info
If one had to box every number object inside another object for some reason (eg keeping track of parental relationships), what would be the performance costs?
Preparation code
<script>
Benchmark.prototype.setup = function() {
function number(n){
return {type:'number',parent:undefined,value:n};
}
function sum(a,b){
return {type:'number',parent:undefined,value:a.value+b.value};
}
boxed_num = number(0);
normal_num = 0;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
normal number sum |
|
pending… |
boxed number sum |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments