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
<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix-min.js"
integrity="sha512-zhHQR0/H5SEBL3Wn6yYSaTTZej12z0hVZKOv3TwCUXT1z5qeqGcXJLLrbERYRScEDDpYIJhPC1fk31gqR783iQ=="
crossorigin="anonymous">
</script>
class CubeDataAdder {
constructor() {
this.cData = new CubeData();
this.renderTarget = {addData(a, b){return a || b;}};
}
addData2() {
if (this.shouldRenderSide(vec3.fromValues(-1, 0, 0))) {
let data = this.cData.side_x0();
this.renderTarget.addData(data, false);
}
if (this.shouldRenderSide(vec3.fromValues(1, 0, 0))) {
let data = this.cData.side_x1();
this.renderTarget.addData(data, false);
}
if (this.shouldRenderSide(vec3.fromValues(0, -1, 0))) {
let data = this.cData.side_y0();
this.renderTarget.addData(data, false);
}
if (this.shouldRenderSide(vec3.fromValues(0, 1, 0))) {
let data = this.cData.side_y1();
this.renderTarget.addData(data, false);
}
if (this.shouldRenderSide(vec3.fromValues(0, 0, -1))) {
let data = this.cData.side_z0();
this.renderTarget.addData(data, false);
}
if (this.shouldRenderSide(vec3.fromValues(0, 0, 1))) {
let data = this.cData.side_z1();
this.renderTarget.addData(data, false);
}
}
addData() {
for (const [offset, name] of _OFFSET_NAMES) {
if (this.shouldRenderSide(offset)) {
let data = this.cData[name]();
this.renderTarget.addData(data, false);
}
}
}
shouldRenderSide(offset) {
return offset[0] == 1;
let pos = vec3.add([], this.pos, offset);
if (!this.world.inRange(pos)) {
return true; // no way for block to be there
}
let side_block = this.world.getBlockUnsafe(pos);
if (!side_block.visible) {
return true;
}
if (
this.block.transparent &&
side_block.transparent &&
offset.some((c) => c > 0)
) {
return false;
}
if (side_block.transparent) {
return true;
}
return false;
}
}
const _OFFSET_NAMES = [
[vec3.fromValues(-1, 0, 0), "side_x0"],
[vec3.fromValues(1, 0, 0), "side_x1"],
[vec3.fromValues(0, -1, 0), "side_y0"],
[vec3.fromValues(0, 1, 0), "side_y1"],
[vec3.fromValues(0, 0, -1), "side_z0"],
[vec3.fromValues(0, 0, 1), "side_z1"],
];
class CubeData {
constructor() {
this.p0 = [7, 9, -5];
this.p1 = [8, 10, -4];
this.doTextures = true;
this.textures = {side: "a", top: "a", bottom: "a"};
this.r = {atlas: {data:{ a: {x0f: 0.11, x1f: 0.19, x0: 0.1, x1: 0.2}}}};
}
side_x0() {
const [x0, y0, z0] = this.p0;
const [_x1, y1, z1] = this.p1;
const sides = {
positions: [x0, y0, z0, x0, y0, z1, x0, y1, z1, x0, y1, z0],
indices: [0, 1, 2, 0, 2, 3],
maxindex: 3,
};
if(this.doTextures) {
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
sides.texCoords = [t0, 1, t1, 1, t1, 0, t0, 0];
}
return sides;
}
side_x1() {
const [_x0, y0, z0] = this.p0;
const [x1, y1, z1] = this.p1;
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
const sides = {
positions: [x1, y0, z0, x1, y1, z0, x1, y1, z1, x1, y0, z1],
indices: [0, 1, 2, 0, 2, 3],
maxindex: 3,
};
if(this.doTextures) {
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
sides.texCoords = [t1, 1, t1, 0, t0, 0, t0, 1];
}
return sides;
}
side_z0() {
const [x0, y0, z0] = this.p0;
const [x1, y1, _z1] = this.p1;
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
const sides = {
positions: [x0, y0, z0, x0, y1, z0, x1, y1, z0, x1, y0, z0],
indices: [0, 1, 2, 0, 2, 3],
maxindex: 3,
};
if(this.doTextures) {
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
sides.texCoords = [t1, 1, t1, 0, t0, 0, t0, 1];
}
return sides;
}
side_z1() {
const [x0, y0, _z0] = this.p0;
const [x1, y1, z1] = this.p1;
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
const sides = {
positions: [x0, y0, z1, x1, y0, z1, x1, y1, z1, x0, y1, z1],
indices: [0, 1, 2, 0, 2, 3],
maxindex: 3,
};
if(this.doTextures) {
const td = this.r.atlas.data[this.textures.side];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
sides.texCoords = [t0, 1, t1, 1, t1, 0, t0, 0];
}
return sides;
}
side_y1() {
const [x0, _y0, z0] = this.p0;
const [x1, y1, z1] = this.p1;
const ret = {
positions: [x0, y1, z0, x0, y1, z1, x1, y1, z1, x1, y1, z0],
indices: [0, 1, 2, 0, 2, 3],
maxindex: 3,
};
if(this.doTextures) {
const td = this.r.atlas.data[this.textures.top];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
ret.texCoords = [t0, 0, t1, 0, t1, 1, t0, 1];
}
return ret;
}
side_y0() {
const [x0, y0, z0] = this.p0;
const [x1, _y1, z1] = this.p1;
const ret = {
positions: [x0, y0, z0, x1, y0, z0, x1, y0, z1, x0, y0, z1],
indices: [0, 1, 2, 0, 2, 3],
maxindex: 3,
};
if(this.doTextures) {
const td = this.r.atlas.data[this.textures.bottom];
const t0 = this.isFar ? td.x0f : td.x0;
const t1 = this.isFar ? td.x1f : td.x1;
ret.texCoords = [t0, 1, t1, 1, t1, 0, t0, 0];
}
return ret;
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Normal |
| ready |
Unrolled |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.