Skip to content

Commit 40f7061

Browse files
committed
Initial three.js benchmark
1 parent 539ab94 commit 40f7061

File tree

3 files changed

+32912
-0
lines changed

3 files changed

+32912
-0
lines changed

JetStreamDriver.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,15 @@ let BENCHMARKS = [
20112011
],
20122012
tags: ["Generators"]
20132013
}),
2014+
new DefaultBenchmark({
2015+
name: "threejs",
2016+
files: [
2017+
"./threejs/three.js",
2018+
"./threejs/benchmark.js",
2019+
],
2020+
deterministicRandom: true,
2021+
tags: ["ThreeJs"],
2022+
}),
20142023
// Wasm
20152024
new WasmEMCCBenchmark({
20162025
name: "HashSet-wasm",

threejs/benchmark.js

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
const NUM_PARTICLES = 8000;
2+
3+
const scene = new THREE.Scene();
4+
scene.background = new THREE.Color(0x111111);
5+
6+
const camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000);
7+
const innerHeight = 1080;
8+
const innerWidth = 1920;
9+
camera.position.z = 500;
10+
11+
const canvas = {}
12+
canvas.addEventListener = function() { }
13+
canvas.style = {}
14+
canvas.getContext = function(kind) {
15+
return {
16+
getExtension(extension) {
17+
if (extension == 'EXT_blend_minmax') {
18+
return {MIN_EXT: 32775, MAX_EXT: 32776}
19+
}
20+
if (extension == 'OES_vertex_array_object') {
21+
return {
22+
createVertexArrayOES() { return 1 },
23+
bindVertexArrayOES() { },
24+
deleteVertexArrayOES() { },
25+
}
26+
}
27+
},
28+
createTexture() { },
29+
bindTexture() { },
30+
texImage2D() { },
31+
texParameteri() { },
32+
uniform1i() { },
33+
uniform1f() { },
34+
uniform2f() { },
35+
uniform3f() { },
36+
uniform4f() { },
37+
clearColor() { },
38+
clear() { },
39+
clearDepth() { },
40+
clearStencil() { },
41+
enable() { },
42+
disable() { },
43+
depthFunc() { },
44+
depthMask() { },
45+
frontFace() { },
46+
cullFace() { },
47+
getContextAttributes() { },
48+
createBuffer() { },
49+
bindBuffer() { },
50+
bufferData() { },
51+
createProgram() { },
52+
attachShader() { },
53+
linkProgram() { },
54+
useProgram() { },
55+
getAttribLocation() { },
56+
getUniformLocation() { },
57+
createShader() { },
58+
shaderSource() { },
59+
compileShader() { },
60+
getShaderParameter() { },
61+
getProgramInfoLog() { return "" },
62+
getShaderInfoLog() { return "" },
63+
getProgramParameter() { },
64+
deleteShader() { },
65+
colorMask() { },
66+
drawElements() { },
67+
lineWidth() { },
68+
drawArrays() { },
69+
viewport() { },
70+
getParameter(param) {
71+
if (param == 34930) { return 16 }
72+
if (param == 35660) { return 16 }
73+
if (param == 3379) { return 8192 }
74+
if (param == 36347) { return 1024 }
75+
if (param == 36348) { return 32 }
76+
if (param == 36349) { return 1024 }
77+
if (param == 35661) { return 80 }
78+
if (param == 7938) { return "WebGL 2.0" }
79+
if (param == 3088) { return [0,0,1024,480] }
80+
if (param == 2978) { return [0,0,1024,480] }
81+
},
82+
MAX_TEXTURE_IMAGE_UNITS: 34930,
83+
MAX_VERTEX_TEXTURE_IMAGE_UNITS: 35660,
84+
MAX_TEXTURE_SIZE: 3379,
85+
MAX_VERTEX_UNIFORM_VECTORS: 36347,
86+
MAX_VARYING_VECTORS: 36348,
87+
MAX_FRAGMENT_UNIFORM_VECTORS: 36349,
88+
MAX_COMBINED_TEXTURE_IMAGE_UNITS: 35661,
89+
VERSION: 7938,
90+
SCISSOR_BOX: 3088,
91+
VIEWPORT: 2978
92+
}
93+
}
94+
95+
const renderer = new THREE.WebGLRenderer({
96+
antialias: false,
97+
canvas,
98+
powerPreference: 'low-power',
99+
precision: 'lowp'
100+
});
101+
renderer.setSize(innerWidth, innerHeight);
102+
103+
const createGeometryParticle = (size) => {
104+
const visibleHeight = 2 * Math.tan(75 * Math.PI/360) * 500;
105+
const radius = (size / innerHeight) * visibleHeight / 2;
106+
107+
// Main circle
108+
const geometry = new THREE.CircleGeometry(radius, 32);
109+
const material = new THREE.MeshBasicMaterial({
110+
color: 0xffffff,
111+
depthTest: false
112+
});
113+
const circle = new THREE.Mesh(geometry, material);
114+
115+
const posArray = geometry.attributes.position.array;
116+
const outlineVertices = [];
117+
for (let i = 3; i < posArray.length; i += 3) {
118+
outlineVertices.push(
119+
new THREE.Vector3(
120+
posArray[i],
121+
posArray[i + 1],
122+
posArray[i + 2]
123+
)
124+
);
125+
}
126+
const outlineGeometry = new THREE.BufferGeometry().setFromPoints(outlineVertices);
127+
const outline = new THREE.LineLoop(
128+
outlineGeometry,
129+
new THREE.LineBasicMaterial({ color: 0x000000, depthTest: false })
130+
);
131+
132+
const group = new THREE.Group();
133+
group.add(circle);
134+
group.add(outline);
135+
return group;
136+
};
137+
138+
// Initialize particles
139+
const particles = [];
140+
for(let i = 0; i < NUM_PARTICLES; i++) {
141+
const size = 10 + Math.random() * 80;
142+
const particle =
143+
createGeometryParticle(size);
144+
145+
// Random initial position
146+
const visibleWidth = 2 * Math.tan(75 * Math.PI/360) * 500 * camera.aspect;
147+
particle.position.set(
148+
THREE.MathUtils.randFloatSpread(visibleWidth),
149+
THREE.MathUtils.randFloatSpread(visibleWidth/camera.aspect),
150+
0
151+
);
152+
153+
// Velocity storage
154+
particle.velocity = new THREE.Vector2(
155+
(Math.random() - 0.5) * 8,
156+
(Math.random() - 0.5) * 8
157+
);
158+
159+
scene.add(particle);
160+
particles.push(particle);
161+
}
162+
163+
// Metrics and animation
164+
const visibleWidth = 2 * Math.tan(75 * Math.PI/360) * 500 * camera.aspect;
165+
const visibleHeight = visibleWidth / camera.aspect;
166+
167+
function animate() {
168+
particles.forEach(particle => {
169+
particle.position.x += particle.velocity.x;
170+
particle.position.y += particle.velocity.y;
171+
172+
// Boundary checks
173+
if(Math.abs(particle.position.x) > visibleWidth/2)
174+
particle.velocity.x *= -1;
175+
if(Math.abs(particle.position.y) > visibleHeight/2)
176+
particle.velocity.y *= -1;
177+
});
178+
179+
renderer.render(scene, camera);
180+
}
181+
182+
class Benchmark {
183+
runIteration() {
184+
animate();
185+
}
186+
}

0 commit comments

Comments
 (0)