Skip to content

Instantly share code, notes, and snippets.

@paulfryzel
Created February 6, 2014 16:25
Show Gist options
  • Save paulfryzel/8847570 to your computer and use it in GitHub Desktop.
Save paulfryzel/8847570 to your computer and use it in GitHub Desktop.
// make objectprint=on disassembler=on -j4 ia32
// d8 --trace-hydrogen --print-opt-code --trace-phase=Z --trace-deopt --code-comments --emit-opt-code-positions --redirect-code-traces --redirect-code-traces-to=code.asm vector3.js
// d8 --prof vector3.js
// v8/tools/mac-tick-processor v8.log
// https://gist.github.com/trevnorris/7712539
// eager: Occurs with unexpected element transitions.
// lazy: Occurs when an assumption is made on a global which no longer holds true.
// soft: As v8 collects type information on functions it will mark dead subgraphs of the
// AST (abstract syntax tree). If one of those marked graphs is called this will cause the
// function to deoptimize and tell v8 more type information needs to be collected.
// debugger: Not really a bailout, but used by the debugger to deoptimize stack frames to allow inspection.
function Vector3(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
Vector3.prototype.magnitude = function() {
//var arg0 = Array.prototype.slice(arguments)[0];
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2));
};
Vector3.prototype.normalize = function() {
var length = this.magnitude();
return new Vector3(this.x / length, this.y / length, this.z / length);
};
var a = new Vector3(3, 1, 2);
var b = new Vector3(3.4, 1.1, 2.5);
print(a.magnitude());
print(a.normalize().magnitude());
function start() {
var aggregate = 0;
for (var i = 0; i < 1e6; i++) {
if (i === 1e3) {
//delete b.y;
//b.y = 1.1;
aggregate += b.magnitude();
//aggregate += b.normalize().magnitude();
} else {
//with (a) { };
//try {
aggregate += a.magnitude();
//aggregate += a.normalize().magnitude();
// } catch(err) {
// }
}
}
return aggregate;
}
print(start());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment