jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
This is a quick experiment to see what the run-time performance difference is between formatted and commented development code (Point) and minimized production code (Boint). Barring the obvious difference of minimized vs formatted, the classes are identical except for the first letter of the constructor.
<script>
/*
Point *a coordinate pair geometry object
versions:
Point(float x, float y)
*/
function Point(X, Y) {
this.x = X;
this.y = Y;
}
Point.prototype = {
/*
point.clone *create clone of this point
versions:
point.clone() returns Point
*/
clone: function clone() {
return new Point(this.x, this.y);
},
/*
Point.move *move the point's coordinates by x and y or by adding another point's coordinates to this point
versions:
Point.move(float x, float y) returns this
Point.move(Point p) returns this
*/
move: function move(a1, a2) {
if (a2) {
this.x += a1;
this.y += a2;
} else {
this.x += a1.x;
this.y += a1.y;
}
return this;
},
/*
Point.moveTo *move this point to a set of coordinates
versions:
Point.moveTo(Point p) returns this
Point.moveTo(float x, float y) returns this
*/
moveTo: function moveTo(a1, a2) {
if (a2) {
this.x = a1;
this.y = a2;
} else {
this.x = a1.x;
this.y = a2.y;
}
return this;
},
/*
Point.equalTo *test to see if a point shares the same coordinates as this
versions:
Point.equalTo(Point p) returns bool
*/
equalTo: function equals(p) {
return this.x === p.x && this.y === p.y;
},
/*
Point.atOrigin *test if this is at the origin coordinates (0,0)
versions:
Point.atOrigin() returns bool
*/
atOrigin: function atOrigin() {
return this.x === 0 && this.y === 0;
},
/*
Point.toOrigin *move this to origin coordinates (0,0)
versions:
Point.toOrigin() returns bool
*/
toOrigin: function toOrigin() {
this.x = 0;
this.y = 0;
return this;
},
/*
Point.distance *get the distance between this and another point
versions:
Point.distance(Point p) returns float
*/
distance: function distance(p) {
var a, b = 0,
m = Math,
x1 = p.x,
x2 = this.x,
y1 = p.y,
y2 = this.y;
a = m.max(x1, x2) - m.min(x1, x2);
b = m.max(y1, y2) - m.min(y1, y2);
return m.sqrt(m.pow(a, 2) + m.pow(b, 2));
},
/*
Point.snapToInt *round coordinates to the nearest corresponding integers
versions:
Point.snapToInt() returns this
*/
snapToInt: function snapToInt() {
var r = Math.round;
this.x = r(this.x);
this.y = r(this.y);
return this;
}
};
function Boint(X,Y){this.x=X;this.y=Y;}Boint.prototype={clone:function clone(){return new Boint(this.x,this.y);},move:function move(a1,a2){if(a2){this.x+=a1;this.y+=a2;}else{this.x+=a1.x;this.y+=a1.y;}return this;},moveTo:function moveTo(a1,a2){if(a2){this.x=a1;this.y=a2;}else{this.x=a1.x;this.y=a2.y;}return this;},equalTo:function equals(p){return this.x===p.x&&this.y===p.y;},atOrigin:function atOrigin(){return this.x===0&&this.y===0;},toOrigin:function toOrigin(){this.x=0;this.y=0;return this;},distance:function distance(p){var a,b=0,m=Math,x1=p.x,x2=this.x,y1=p.y,y2=this.y;a=m.max(x1,x2)-m.min(x1,x2);b=m.max(y1,y2)-m.min(y1,y2);return m.sqrt(m.pow(a,2)+m.pow(b,2));},snapToInt:function snapToInt(){var r=Math.round;this.x=r(this.x);this.y=r(this.y);return this;}};
var p1 = new Point();
var p2 = new Point(2,2);
var b1 = new Boint();
var b2 = new Boint(2,2);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Formatted Constructor |
| ready |
Minimized Constructor |
| ready |
formatted function |
| ready |
minimized function |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.