Skip to content

Commit c706ca3

Browse files
committed
Add fixtures
1 parent 809f81e commit c706ca3

File tree

14 files changed

+1683
-30610
lines changed

14 files changed

+1683
-30610
lines changed

.github/workflows/CI.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ jobs:
3232
run: |
3333
rustup toolchain install nightly
3434
cargo +nightly run -p cpu-features --features nightly
35-
- name: Run benchmarks
35+
- uses: actions/setup-node@v5
36+
with:
37+
node-version: 22
38+
cache: 'yarn'
39+
- name: Install dependencies
40+
run: yarn install
41+
- name: Download fixtures
42+
run: node download-fixtures.js
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
- name: Run tests
3646
run: cargo test
3747

3848
bench:
@@ -55,6 +65,16 @@ jobs:
5565
uses: dtolnay/rust-toolchain@stable
5666
with:
5767
targets: ${{ matrix.settings.target }}
68+
- uses: actions/setup-node@v5
69+
with:
70+
node-version: 22
71+
cache: 'yarn'
72+
- name: Install dependencies
73+
run: yarn install
74+
- name: Download fixtures
75+
run: node download-fixtures.js
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5878
- name: Run benchmarks
5979
run: cargo bench
6080
env:

.gitignore

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,148 @@
11
/target
2+
3+
4+
### Created by https://www.gitignore.io
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
.pnpm-debug.log*
14+
15+
# Diagnostic reports (https://nodejs.org/api/report.html)
16+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17+
18+
# Runtime data
19+
pids
20+
*.pid
21+
*.seed
22+
*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
lib-cov
26+
27+
# Coverage directory used by tools like istanbul
28+
coverage
29+
*.lcov
30+
31+
# nyc test coverage
32+
.nyc_output
33+
34+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35+
.grunt
36+
37+
# Bower dependency directory (https://bower.io/)
38+
bower_components
39+
40+
# node-waf configuration
41+
.lock-wscript
42+
43+
# Compiled binary addons (https://nodejs.org/api/addons.html)
44+
build/Release
45+
46+
# Dependency directories
47+
node_modules/
48+
jspm_packages/
49+
50+
# Snowpack dependency directory (https://snowpack.dev/)
51+
web_modules/
52+
53+
# TypeScript cache
54+
*.tsbuildinfo
55+
56+
# Optional npm cache directory
57+
.npm
58+
59+
# Optional eslint cache
60+
.eslintcache
61+
62+
# Optional stylelint cache
63+
.stylelintcache
64+
65+
# Microbundle cache
66+
.rpt2_cache/
67+
.rts2_cache_cjs/
68+
.rts2_cache_es/
69+
.rts2_cache_umd/
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variable files
81+
.env
82+
.env.development.local
83+
.env.test.local
84+
.env.production.local
85+
.env.local
86+
87+
# parcel-bundler cache (https://parceljs.org/)
88+
.cache
89+
.parcel-cache
90+
91+
# Next.js build output
92+
.next
93+
out
94+
95+
# Nuxt.js build / generate output
96+
.nuxt
97+
dist
98+
99+
# Gatsby files
100+
.cache/
101+
# Comment in the public line in if your project uses Gatsby and not Next.js
102+
# https://nextjs.org/blog/next-9-1#public-directory-support
103+
# public
104+
105+
# vuepress build output
106+
.vuepress/dist
107+
108+
# vuepress v2.x temp and cache directory
109+
.temp
110+
.cache
111+
112+
# Docusaurus cache and generated files
113+
.docusaurus
114+
115+
# Serverless directories
116+
.serverless/
117+
118+
# FuseBox cache
119+
.fusebox/
120+
121+
# DynamoDB Local files
122+
.dynamodb/
123+
124+
# TernJS port file
125+
.tern-port
126+
127+
# Stores VSCode versions used for testing VSCode extensions
128+
.vscode-test
129+
130+
# yarn v2
131+
.yarn/cache
132+
.yarn/unplugged
133+
.yarn/build-state.yml
134+
.yarn/install-state.gz
135+
.pnp.*
136+
137+
### Node Patch ###
138+
# Serverless Webpack directories
139+
.webpack/
140+
141+
# Optional stylelint cache
142+
.stylelintcache
143+
144+
# SvelteKit build / generate output
145+
.svelte-kit
146+
147+
*.tar.gz
148+
fixtures

.yarn/releases/yarn-4.10.2.cjs

Lines changed: 942 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarnPath: .yarn/releases/yarn-4.10.2.cjs
2+
nodeLinker: node-modules

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ anyhow = "1"
2020

2121
[dev-dependencies]
2222
criterion = { version = "0.7", features = ["html_reports"] }
23+
glob = "0.3"
2324
serde_json = "1"
2425
v_jsonescape = "0.7"
2526
json-escape = "0.1.1"

benches/escape.rs

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,93 @@
1-
use std::hint::black_box;
1+
use std::{fs, hint::black_box};
22

33
use criterion::{Criterion, criterion_group, criterion_main};
44

55
use json_escape_simd::{escape, escape_generic};
66

7-
const FIXTURE: &str = include_str!("../cal.com.tsx");
7+
fn get_rxjs_sources() -> Vec<String> {
8+
let rxjs_paths = glob::glob("node_modules/rxjs/src/**/*.ts").unwrap();
9+
let mut sources = Vec::new();
10+
for entry in rxjs_paths {
11+
let p = entry.unwrap();
12+
if fs::metadata(&p).unwrap().is_file() {
13+
sources.push(fs::read_to_string(&p).unwrap());
14+
}
15+
}
16+
sources
17+
}
18+
19+
fn get_fixture_sources() -> Vec<String> {
20+
let ts_paths = glob::glob("fixtures/**/*.ts").unwrap();
21+
let tsx_paths = glob::glob("fixtures/**/*.tsx").unwrap();
22+
let js_paths = glob::glob("fixtures/**/*.js").unwrap();
23+
let mjs_paths = glob::glob("fixtures/**/*.mjs").unwrap();
24+
let cjs_paths = glob::glob("fixtures/**/*.cjs").unwrap();
25+
let mut sources = Vec::new();
26+
for entry in ts_paths
27+
.chain(tsx_paths)
28+
.chain(js_paths)
29+
.chain(mjs_paths)
30+
.chain(cjs_paths)
31+
{
32+
let p = entry.unwrap();
33+
if fs::metadata(&p).unwrap().is_file() {
34+
sources.push(fs::read_to_string(&p).unwrap());
35+
}
36+
}
37+
sources
38+
}
839

9-
fn criterion_benchmark(c: &mut Criterion) {
10-
c.bench_function("escape simd", |b| b.iter(|| black_box(escape(FIXTURE))));
11-
c.bench_function("escape v_jsonescape", |b| {
12-
b.iter(|| black_box(v_jsonescape::escape(FIXTURE).to_string()))
40+
fn run_benchmarks(c: &mut Criterion, sources: &[String], prefix: &str) {
41+
c.bench_function(&format!("{} escape simd", prefix), |b| {
42+
b.iter(|| {
43+
for source in sources {
44+
black_box(escape(source));
45+
}
46+
})
47+
});
48+
c.bench_function(&format!("{} escape v_jsonescape", prefix), |b| {
49+
b.iter(|| {
50+
for source in sources {
51+
black_box(v_jsonescape::escape(source).to_string());
52+
}
53+
})
1354
});
14-
c.bench_function("json-escape", |b| {
15-
b.iter(|| black_box(json_escape::escape_str(FIXTURE).collect::<String>()))
55+
c.bench_function(&format!("{} json-escape", prefix), |b| {
56+
b.iter(|| {
57+
for source in sources {
58+
black_box(json_escape::escape_str(source).collect::<String>());
59+
}
60+
})
1661
});
17-
c.bench_function("escape generic", |b| {
18-
b.iter(|| black_box(escape_generic(FIXTURE)))
62+
c.bench_function(&format!("{} escape generic", prefix), |b| {
63+
b.iter(|| {
64+
for source in sources {
65+
black_box(escape_generic(source));
66+
}
67+
})
1968
});
20-
c.bench_function("serde_json", |b| {
21-
b.iter(|| black_box(serde_json::to_string(FIXTURE).unwrap()))
69+
c.bench_function(&format!("{} serde_json", prefix), |b| {
70+
b.iter(|| {
71+
for source in sources {
72+
black_box(serde_json::to_string(source).unwrap());
73+
}
74+
})
2275
});
2376
}
2477

25-
criterion_group!(benches, criterion_benchmark);
78+
fn rxjs_benchmark(c: &mut Criterion) {
79+
let sources = get_rxjs_sources();
80+
if !sources.is_empty() {
81+
run_benchmarks(c, &sources, "rxjs");
82+
}
83+
}
84+
85+
fn fixtures_benchmark(c: &mut Criterion) {
86+
let sources = get_fixture_sources();
87+
if !sources.is_empty() {
88+
run_benchmarks(c, &sources, "fixtures");
89+
}
90+
}
91+
92+
criterion_group!(benches, rxjs_benchmark, fixtures_benchmark);
2693
criterion_main!(benches);

0 commit comments

Comments
 (0)