Benchmark for KCL parser (#664)
* KCL benchmarks * CI for benchmarks * More specific name for benchmark * Benchmark the right directory * Format
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/workflows/cargo-clippy.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/cargo-clippy.yml
									
									
									
									
										vendored
									
									
								
							| @ -54,4 +54,4 @@ jobs: | ||||
|       - name: Run clippy | ||||
|         run: | | ||||
|           cd "${{ matrix.dir }}" | ||||
|           cargo clippy --all --tests -- -D warnings | ||||
|           cargo clippy --all --tests --benches -- -D warnings | ||||
|  | ||||
							
								
								
									
										37
									
								
								.github/workflows/cargo-criterion.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								.github/workflows/cargo-criterion.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| on: | ||||
|   push: | ||||
|     branches: | ||||
|       - main | ||||
|     paths: | ||||
|       - '**.rs' | ||||
|       - '**/Cargo.toml' | ||||
|       - '**/Cargo.lock' | ||||
|       - '**/rust-toolchain.toml' | ||||
|       - .github/workflows/cargo-criterion.yml | ||||
|   pull_request: | ||||
|     paths: | ||||
|       - '**.rs' | ||||
|       - '**/Cargo.toml' | ||||
|       - '**/Cargo.lock' | ||||
|       - '**/rust-toolchain.toml' | ||||
|       - .github/workflows/cargo-criterion.yml | ||||
|   workflow_dispatch: | ||||
| permissions: read-all | ||||
| name: cargo criterion | ||||
| jobs: | ||||
|   cargocriterion: | ||||
|     name: cargo criterion | ||||
|     runs-on: ubuntu-latest-8-cores | ||||
|     steps: | ||||
|       - uses: actions/checkout@v4 | ||||
|       - uses: dtolnay/rust-toolchain@stable | ||||
|       - name: Install dependencies | ||||
|         run: | | ||||
|           cargo install cargo-criterion | ||||
|       - name: Rust Cache | ||||
|         uses: Swatinem/rust-cache@v2.6.1 | ||||
|       - name: Benchmark kcl library | ||||
|         shell: bash | ||||
|         run: |- | ||||
|           cd src/wasm-lib/kcl; cargo criterion | ||||
|  | ||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -22,6 +22,8 @@ npm-debug.log* | ||||
| yarn-debug.log* | ||||
| yarn-error.log* | ||||
|  | ||||
| src/wasm-lib/.idea | ||||
|  | ||||
| # rust | ||||
| src/wasm-lib/target | ||||
| src/wasm-lib/bindings | ||||
|  | ||||
| @ -65,7 +65,7 @@ | ||||
|     "pretest": "yarn remove-importmeta", | ||||
|     "test": "vitest --mode development", | ||||
|     "test:nowatch": "vitest run --mode development", | ||||
|     "test:rust": "(cd src/wasm-lib && cargo test --all && cargo clippy --all --tests)", | ||||
|     "test:rust": "(cd src/wasm-lib && cargo test --all && cargo clippy --all --tests --benches)", | ||||
|     "test:cov": "vitest run --coverage --mode development", | ||||
|     "simpleserver:ci": "yarn pretest && http-server ./public --cors -p 3000 &", | ||||
|     "simpleserver": "yarn pretest && http-server ./public --cors -p 3000", | ||||
|  | ||||
							
								
								
									
										128
									
								
								src/wasm-lib/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										128
									
								
								src/wasm-lib/Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -63,6 +63,12 @@ dependencies = [ | ||||
|  "libc", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "anes" | ||||
| version = "0.1.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" | ||||
|  | ||||
| [[package]] | ||||
| name = "anstream" | ||||
| version = "0.5.0" | ||||
| @ -337,6 +343,12 @@ dependencies = [ | ||||
|  "serde", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "cast" | ||||
| version = "0.3.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" | ||||
|  | ||||
| [[package]] | ||||
| name = "cc" | ||||
| version = "1.0.83" | ||||
| @ -374,6 +386,33 @@ dependencies = [ | ||||
|  "windows-targets 0.48.5", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "ciborium" | ||||
| version = "0.2.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" | ||||
| dependencies = [ | ||||
|  "ciborium-io", | ||||
|  "ciborium-ll", | ||||
|  "serde", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "ciborium-io" | ||||
| version = "0.2.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" | ||||
|  | ||||
| [[package]] | ||||
| name = "ciborium-ll" | ||||
| version = "0.2.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" | ||||
| dependencies = [ | ||||
|  "ciborium-io", | ||||
|  "half 1.8.2", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "clang-sys" | ||||
| version = "1.6.1" | ||||
| @ -507,6 +546,42 @@ dependencies = [ | ||||
|  "cfg-if", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "criterion" | ||||
| version = "0.5.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" | ||||
| dependencies = [ | ||||
|  "anes", | ||||
|  "cast", | ||||
|  "ciborium", | ||||
|  "clap", | ||||
|  "criterion-plot", | ||||
|  "is-terminal", | ||||
|  "itertools 0.10.5", | ||||
|  "num-traits", | ||||
|  "once_cell", | ||||
|  "oorandom", | ||||
|  "plotters", | ||||
|  "rayon", | ||||
|  "regex", | ||||
|  "serde", | ||||
|  "serde_derive", | ||||
|  "serde_json", | ||||
|  "tinytemplate", | ||||
|  "walkdir", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "criterion-plot" | ||||
| version = "0.5.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" | ||||
| dependencies = [ | ||||
|  "cast", | ||||
|  "itertools 0.10.5", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "crossbeam-channel" | ||||
| version = "0.5.8" | ||||
| @ -716,7 +791,7 @@ checksum = "832a761f35ab3e6664babfbdc6cef35a4860e816ec3916dcfd0882954e98a8a8" | ||||
| dependencies = [ | ||||
|  "bit_field", | ||||
|  "flume", | ||||
|  "half", | ||||
|  "half 2.2.1", | ||||
|  "lebe", | ||||
|  "miniz_oxide", | ||||
|  "rayon-core", | ||||
| @ -983,6 +1058,12 @@ dependencies = [ | ||||
|  "tracing", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "half" | ||||
| version = "1.8.2" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" | ||||
|  | ||||
| [[package]] | ||||
| name = "half" | ||||
| version = "2.2.1" | ||||
| @ -1287,6 +1368,7 @@ dependencies = [ | ||||
|  "async-trait", | ||||
|  "bson", | ||||
|  "clap", | ||||
|  "criterion", | ||||
|  "dashmap", | ||||
|  "derive-docs", | ||||
|  "expectorate", | ||||
| @ -1606,6 +1688,12 @@ version = "0.1.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "44d11de466f4a3006fe8a5e7ec84e93b79c70cb992ae0aa0eb631ad2df8abfe2" | ||||
|  | ||||
| [[package]] | ||||
| name = "oorandom" | ||||
| version = "11.1.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" | ||||
|  | ||||
| [[package]] | ||||
| name = "openapitor" | ||||
| version = "0.0.9" | ||||
| @ -1839,6 +1927,34 @@ version = "0.3.27" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" | ||||
|  | ||||
| [[package]] | ||||
| name = "plotters" | ||||
| version = "0.3.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" | ||||
| dependencies = [ | ||||
|  "num-traits", | ||||
|  "plotters-backend", | ||||
|  "plotters-svg", | ||||
|  "wasm-bindgen", | ||||
|  "web-sys", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "plotters-backend" | ||||
| version = "0.3.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" | ||||
|  | ||||
| [[package]] | ||||
| name = "plotters-svg" | ||||
| version = "0.3.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" | ||||
| dependencies = [ | ||||
|  "plotters-backend", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "png" | ||||
| version = "0.17.10" | ||||
| @ -2853,6 +2969,16 @@ dependencies = [ | ||||
|  "time-core", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "tinytemplate" | ||||
| version = "1.2.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" | ||||
| dependencies = [ | ||||
|  "serde", | ||||
|  "serde_json", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "tinyvec" | ||||
| version = "1.6.0" | ||||
|  | ||||
| @ -50,7 +50,12 @@ panic = "abort" | ||||
| debug = true | ||||
|  | ||||
| [dev-dependencies] | ||||
| criterion = "0.5.1" | ||||
| expectorate = "1.0.7" | ||||
| itertools = "0.11.0" | ||||
| pretty_assertions = "1.4.0" | ||||
| tokio = { version = "1.32.0", features = ["rt-multi-thread", "macros", "time"] } | ||||
|  | ||||
| [[bench]] | ||||
| name = "compiler_benchmark" | ||||
| harness = false | ||||
|  | ||||
							
								
								
									
										27
									
								
								src/wasm-lib/kcl/benches/compiler_benchmark.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/wasm-lib/kcl/benches/compiler_benchmark.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| use criterion::{criterion_group, criterion_main, Criterion}; | ||||
|  | ||||
| pub fn criterion_benchmark(c: &mut Criterion) { | ||||
|     c.bench_function("parse + lex cube program", |b| b.iter(lex_and_parse_cube)); | ||||
| } | ||||
|  | ||||
| fn lex_and_parse_cube() { | ||||
|     let program = r#" | ||||
| fn cube = (pos, scale) => { | ||||
|   const sg = startSketchAt(pos) | ||||
|     |> line([0, scale], %) | ||||
|     |> line([scale, 0], %) | ||||
|     |> line([0, -scale], %) | ||||
|  | ||||
|   return sg | ||||
| } | ||||
|  | ||||
| const b1 = cube([0,0], 10) | ||||
| const pt1 = b1[0] | ||||
| show(b1)"#; | ||||
|     let tokens = kcl_lib::tokeniser::lexer(program); | ||||
|     let parser = kcl_lib::parser::Parser::new(tokens); | ||||
|     parser.ast().unwrap(); | ||||
| } | ||||
|  | ||||
| criterion_group!(benches, criterion_benchmark); | ||||
| criterion_main!(benches); | ||||
		Reference in New Issue
	
	Block a user