Skip to content

Commit ffb3a54

Browse files
committed
Add benchmark
1 parent 0662144 commit ffb3a54

File tree

382 files changed

+59137
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

382 files changed

+59137
-12
lines changed

.DS_Store

6 KB
Binary file not shown.

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@ description = "manipulate string like wizards"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11+
glob = "0.3.1"
1112
index_vec = { version = "0.1.3" }
1213
rustc-hash = { version = "1.1.0" }
14+
15+
16+
[dev-dependencies]
17+
glob = "0.3.1"
18+
criterion = { version = "0.4" }
19+
20+
[[bench]]
21+
name = "joiner_join"
22+
harness = false

benches/joiner_join.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
3+
fn get_bunch_of_strings() -> Vec<String> {
4+
let files = glob::glob("fixtures/threejs_src/**/*.js").unwrap();
5+
let mut files = files
6+
.into_iter()
7+
.map(|p| p.unwrap().canonicalize().unwrap())
8+
.collect::<Vec<_>>();
9+
files.sort();
10+
let stirngs = files
11+
.iter()
12+
.map(|p| std::fs::read_to_string(p).unwrap())
13+
.collect::<Vec<_>>();
14+
15+
let mut ret = vec![];
16+
for _ in 0..10 {
17+
ret.extend(stirngs.clone());
18+
}
19+
ret
20+
}
21+
22+
fn criterion_benchmark(c: &mut Criterion) {
23+
let bunch_of_strings = get_bunch_of_strings();
24+
25+
let mut joiner = string_wizard::Joiner::new();
26+
bunch_of_strings.clone().into_iter().for_each(|s| {
27+
joiner.append_raw(s);
28+
});
29+
c.bench_function("Joiner#join", |b| b.iter(|| black_box(joiner.join())));
30+
c.bench_function("Vec#concat", |b| {
31+
b.iter(|| black_box(bunch_of_strings.concat()))
32+
});
33+
c.bench_function("manual_push", |b| {
34+
b.iter(|| {
35+
let mut output = String::new();
36+
bunch_of_strings.iter().for_each(|s| {
37+
output.push_str(s);
38+
});
39+
black_box(output)
40+
})
41+
});
42+
c.bench_function("manual_push_with_cap", |b| {
43+
b.iter(|| {
44+
let cap: usize = bunch_of_strings.iter().map(|s| s.len()).sum();
45+
let mut output = String::with_capacity(cap);
46+
bunch_of_strings.iter().for_each(|s| {
47+
output.push_str(s);
48+
});
49+
black_box(output)
50+
})
51+
});
52+
}
53+
54+
criterion_group!(benches, criterion_benchmark);
55+
criterion_main!(benches);

fixtures/.DS_Store

6 KB
Binary file not shown.

fixtures/threejs_src/.DS_Store

10 KB
Binary file not shown.

fixtures/threejs_src/Three.Legacy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

fixtures/threejs_src/Three.js

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
import { REVISION } from './constants.js';
2+
3+
export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js';
4+
export { WebGL3DRenderTarget } from './renderers/WebGL3DRenderTarget.js';
5+
export { WebGLMultipleRenderTargets } from './renderers/WebGLMultipleRenderTargets.js';
6+
export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js';
7+
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
8+
export { WebGLRenderer } from './renderers/WebGLRenderer.js';
9+
export { WebGL1Renderer } from './renderers/WebGL1Renderer.js';
10+
export { ShaderLib } from './renderers/shaders/ShaderLib.js';
11+
export { UniformsLib } from './renderers/shaders/UniformsLib.js';
12+
export { UniformsUtils } from './renderers/shaders/UniformsUtils.js';
13+
export { ShaderChunk } from './renderers/shaders/ShaderChunk.js';
14+
export { FogExp2 } from './scenes/FogExp2.js';
15+
export { Fog } from './scenes/Fog.js';
16+
export { Scene } from './scenes/Scene.js';
17+
export { Sprite } from './objects/Sprite.js';
18+
export { LOD } from './objects/LOD.js';
19+
export { SkinnedMesh } from './objects/SkinnedMesh.js';
20+
export { Skeleton } from './objects/Skeleton.js';
21+
export { Bone } from './objects/Bone.js';
22+
export { Mesh } from './objects/Mesh.js';
23+
export { InstancedMesh } from './objects/InstancedMesh.js';
24+
export { LineSegments } from './objects/LineSegments.js';
25+
export { LineLoop } from './objects/LineLoop.js';
26+
export { Line } from './objects/Line.js';
27+
export { Points } from './objects/Points.js';
28+
export { Group } from './objects/Group.js';
29+
export { VideoTexture } from './textures/VideoTexture.js';
30+
export { FramebufferTexture } from './textures/FramebufferTexture.js';
31+
export { Source } from './textures/Source.js';
32+
export { DataTexture } from './textures/DataTexture.js';
33+
export { DataArrayTexture } from './textures/DataArrayTexture.js';
34+
export { Data3DTexture } from './textures/Data3DTexture.js';
35+
export { CompressedTexture } from './textures/CompressedTexture.js';
36+
export { CompressedArrayTexture } from './textures/CompressedArrayTexture.js';
37+
export { CompressedCubeTexture } from './textures/CompressedCubeTexture.js';
38+
export { CubeTexture } from './textures/CubeTexture.js';
39+
export { CanvasTexture } from './textures/CanvasTexture.js';
40+
export { DepthTexture } from './textures/DepthTexture.js';
41+
export { Texture } from './textures/Texture.js';
42+
export * from './geometries/Geometries.js';
43+
export * from './materials/Materials.js';
44+
export { AnimationLoader } from './loaders/AnimationLoader.js';
45+
export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js';
46+
export { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
47+
export { DataTextureLoader } from './loaders/DataTextureLoader.js';
48+
export { TextureLoader } from './loaders/TextureLoader.js';
49+
export { ObjectLoader } from './loaders/ObjectLoader.js';
50+
export { MaterialLoader } from './loaders/MaterialLoader.js';
51+
export { BufferGeometryLoader } from './loaders/BufferGeometryLoader.js';
52+
export { DefaultLoadingManager, LoadingManager } from './loaders/LoadingManager.js';
53+
export { ImageLoader } from './loaders/ImageLoader.js';
54+
export { ImageBitmapLoader } from './loaders/ImageBitmapLoader.js';
55+
export { FileLoader } from './loaders/FileLoader.js';
56+
export { Loader } from './loaders/Loader.js';
57+
export { LoaderUtils } from './loaders/LoaderUtils.js';
58+
export { Cache } from './loaders/Cache.js';
59+
export { AudioLoader } from './loaders/AudioLoader.js';
60+
export { SpotLight } from './lights/SpotLight.js';
61+
export { PointLight } from './lights/PointLight.js';
62+
export { RectAreaLight } from './lights/RectAreaLight.js';
63+
export { HemisphereLight } from './lights/HemisphereLight.js';
64+
export { DirectionalLight } from './lights/DirectionalLight.js';
65+
export { AmbientLight } from './lights/AmbientLight.js';
66+
export { Light } from './lights/Light.js';
67+
export { LightProbe } from './lights/LightProbe.js';
68+
export { StereoCamera } from './cameras/StereoCamera.js';
69+
export { PerspectiveCamera } from './cameras/PerspectiveCamera.js';
70+
export { OrthographicCamera } from './cameras/OrthographicCamera.js';
71+
export { CubeCamera } from './cameras/CubeCamera.js';
72+
export { ArrayCamera } from './cameras/ArrayCamera.js';
73+
export { Camera } from './cameras/Camera.js';
74+
export { AudioListener } from './audio/AudioListener.js';
75+
export { PositionalAudio } from './audio/PositionalAudio.js';
76+
export { AudioContext } from './audio/AudioContext.js';
77+
export { AudioAnalyser } from './audio/AudioAnalyser.js';
78+
export { Audio } from './audio/Audio.js';
79+
export { VectorKeyframeTrack } from './animation/tracks/VectorKeyframeTrack.js';
80+
export { StringKeyframeTrack } from './animation/tracks/StringKeyframeTrack.js';
81+
export { QuaternionKeyframeTrack } from './animation/tracks/QuaternionKeyframeTrack.js';
82+
export { NumberKeyframeTrack } from './animation/tracks/NumberKeyframeTrack.js';
83+
export { ColorKeyframeTrack } from './animation/tracks/ColorKeyframeTrack.js';
84+
export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js';
85+
export { PropertyMixer } from './animation/PropertyMixer.js';
86+
export { PropertyBinding } from './animation/PropertyBinding.js';
87+
export { KeyframeTrack } from './animation/KeyframeTrack.js';
88+
export { AnimationUtils } from './animation/AnimationUtils.js';
89+
export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js';
90+
export { AnimationMixer } from './animation/AnimationMixer.js';
91+
export { AnimationClip } from './animation/AnimationClip.js';
92+
export { AnimationAction } from './animation/AnimationAction.js';
93+
export { RenderTarget } from './core/RenderTarget.js';
94+
export { Uniform } from './core/Uniform.js';
95+
export { UniformsGroup } from './core/UniformsGroup.js';
96+
export { InstancedBufferGeometry } from './core/InstancedBufferGeometry.js';
97+
export { BufferGeometry } from './core/BufferGeometry.js';
98+
export { InterleavedBufferAttribute } from './core/InterleavedBufferAttribute.js';
99+
export { InstancedInterleavedBuffer } from './core/InstancedInterleavedBuffer.js';
100+
export { InterleavedBuffer } from './core/InterleavedBuffer.js';
101+
export { InstancedBufferAttribute } from './core/InstancedBufferAttribute.js';
102+
export { GLBufferAttribute } from './core/GLBufferAttribute.js';
103+
export * from './core/BufferAttribute.js';
104+
export { Object3D } from './core/Object3D.js';
105+
export { Raycaster } from './core/Raycaster.js';
106+
export { Layers } from './core/Layers.js';
107+
export { EventDispatcher } from './core/EventDispatcher.js';
108+
export { Clock } from './core/Clock.js';
109+
export { QuaternionLinearInterpolant } from './math/interpolants/QuaternionLinearInterpolant.js';
110+
export { LinearInterpolant } from './math/interpolants/LinearInterpolant.js';
111+
export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js';
112+
export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js';
113+
export { Interpolant } from './math/Interpolant.js';
114+
export { Triangle } from './math/Triangle.js';
115+
export { MathUtils } from './math/MathUtils.js';
116+
export { Spherical } from './math/Spherical.js';
117+
export { Cylindrical } from './math/Cylindrical.js';
118+
export { Plane } from './math/Plane.js';
119+
export { Frustum } from './math/Frustum.js';
120+
export { Sphere } from './math/Sphere.js';
121+
export { Ray } from './math/Ray.js';
122+
export { Matrix4 } from './math/Matrix4.js';
123+
export { Matrix3 } from './math/Matrix3.js';
124+
export { Box3 } from './math/Box3.js';
125+
export { Box2 } from './math/Box2.js';
126+
export { Line3 } from './math/Line3.js';
127+
export { Euler } from './math/Euler.js';
128+
export { Vector4 } from './math/Vector4.js';
129+
export { Vector3 } from './math/Vector3.js';
130+
export { Vector2 } from './math/Vector2.js';
131+
export { Quaternion } from './math/Quaternion.js';
132+
export { Color } from './math/Color.js';
133+
export { ColorManagement } from './math/ColorManagement.js';
134+
export { SphericalHarmonics3 } from './math/SphericalHarmonics3.js';
135+
export { SpotLightHelper } from './helpers/SpotLightHelper.js';
136+
export { SkeletonHelper } from './helpers/SkeletonHelper.js';
137+
export { PointLightHelper } from './helpers/PointLightHelper.js';
138+
export { HemisphereLightHelper } from './helpers/HemisphereLightHelper.js';
139+
export { GridHelper } from './helpers/GridHelper.js';
140+
export { PolarGridHelper } from './helpers/PolarGridHelper.js';
141+
export { DirectionalLightHelper } from './helpers/DirectionalLightHelper.js';
142+
export { CameraHelper } from './helpers/CameraHelper.js';
143+
export { BoxHelper } from './helpers/BoxHelper.js';
144+
export { Box3Helper } from './helpers/Box3Helper.js';
145+
export { PlaneHelper } from './helpers/PlaneHelper.js';
146+
export { ArrowHelper } from './helpers/ArrowHelper.js';
147+
export { AxesHelper } from './helpers/AxesHelper.js';
148+
export * from './extras/curves/Curves.js';
149+
export { Shape } from './extras/core/Shape.js';
150+
export { Path } from './extras/core/Path.js';
151+
export { ShapePath } from './extras/core/ShapePath.js';
152+
export { CurvePath } from './extras/core/CurvePath.js';
153+
export { Curve } from './extras/core/Curve.js';
154+
export { DataUtils } from './extras/DataUtils.js';
155+
export { ImageUtils } from './extras/ImageUtils.js';
156+
export { ShapeUtils } from './extras/ShapeUtils.js';
157+
export { PMREMGenerator } from './extras/PMREMGenerator.js';
158+
export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
159+
export { createCanvasElement } from './utils.js';
160+
export * from './constants.js';
161+
export * from './Three.Legacy.js';
162+
163+
if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
164+
165+
__THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
166+
revision: REVISION,
167+
} } ) );
168+
169+
}
170+
171+
if ( typeof window !== 'undefined' ) {
172+
173+
if ( window.__THREE__ ) {
174+
175+
console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
176+
177+
} else {
178+
179+
window.__THREE__ = REVISION;
180+
181+
}
182+
183+
}

0 commit comments

Comments
 (0)