Internal definition of class constants vs passing params
JavaScript performance comparison
Info
A test to determine whether, if some data is going to be standard across all objects of a type/prototype/class, it is more perfomant to:
a: Define the data in the object constructor function.
b: Define the data as a prototype field.
c: Define the data outside the scope of the object function and pass as
a parameter to the constructor function.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var defaults = {
radius:400,
up:1
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Using object constructor function |
|
pending… |
Using a prototype field |
|
pending… |
Pass a parameter |
|
pending… |
Using a prototype function |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments