Skip to content

Add some toolchain benchmarks to test_benchmark.py#26304

Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:toolchain_benchmark
Feb 19, 2026
Merged

Add some toolchain benchmarks to test_benchmark.py#26304
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:toolchain_benchmark

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Feb 19, 2026

These measure the performance of the compiler itself relative to clang.

The output looks like this:

[1/2] test_emcc_compile_hello (test_benchmark.benchmark.test_emcc_compile_hello) ...
        clang: mean: 0.062 (+-0.001) secs  median: 0.062  range: 0.060-0.063  (noise: 2.354%)  (5 runs)   Relative: No baseline recorded yet
         emcc: mean: 0.166 (+-0.004) secs  median: 0.166  range: 0.159-0.171  (noise: 2.374%)  (5 runs)   Relative: 2.69 X slower
ok
[2/2] test_emcc_noop (test_benchmark.benchmark.test_emcc_noop) ...
        clang: mean: 0.044 (+-0.001) secs  median: 0.045  range: 0.042-0.045  (noise: 2.469%)  (5 runs)   Relative: No baseline recorded yet
         emcc: mean: 0.124 (+-0.003) secs  median: 0.124  range: 0.121-0.127  (noise: 2.169%)  (5 runs)   Relative: 2.82 X slower
ok

@sbc100 sbc100 enabled auto-merge (squash) February 19, 2026 01:27
@sbc100 sbc100 force-pushed the toolchain_benchmark branch from 76660ff to 0186a0c Compare February 19, 2026 17:47
benchmarkers = [
ToolchainBenchmarker('clang', [CLANG_CC]),
ToolchainBenchmarker('emcc', [EMCC]),
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not add these to the normal toplevel list of benchmarkers? That is, we have a "primes" benchmark, and we could have a "hello world" benchmark. And there could be a Benchmarker that just compiles in emcc or clang and doesn't run. That could run on all the benchmarks in principle.

Then, picking the right Benchmarkers using the env var, and the right benchmarks using benchmark.test_*, you can get the results you want iiuc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lot of the existing benchmarks would not work with these benchmarkers I fear since they anything in the build phase and instead run the compiler in the run phase (which doesn't have any of the build arguments such as filename, shared_args, emcc_args, native_args, native_exec, lib_builder.

For very simple cases it does work to just do the compiling during run. So I added these new benchmarkers to the named list so folks can try them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a lot of other benchmarks might not work - but that's fine I think as users can pick which they want?

Now that we have lines 398-399, do we need 559-562? That is, can't we run these benchmarks the normal way? I am just trying to avoid adding a second "harness" that iterates over benchmarks, that handles using the first benchmarker as the baseline (568-571), etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to re-use do_bennchmark for these, but its different enough I think it warrants keeping this simple/separate do_toolchain_benchmark.

For example, with the toolchain benchmark there is no "src" or "name" to pass.

Maybe we can find a way to merge them later, but this seems OK for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'd hope we can make src, name optional somehow, but I guess this new function is not a huge amount of code, so I won't object strongly.

@sbc100 sbc100 force-pushed the toolchain_benchmark branch 2 times, most recently from 53eaae8 to 83196d5 Compare February 19, 2026 18:02
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % typos

benchmarkers = [
ToolchainBenchmarker('clang', [CLANG_CC]),
ToolchainBenchmarker('emcc', [EMCC]),
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'd hope we can make src, name optional somehow, but I guess this new function is not a huge amount of code, so I won't object strongly.

These measure the performance of the compiler itself relative to clang.

The output looks like this:

```
[1/2] test_emcc_compile_hello (test_benchmark.benchmark.test_emcc_compile_hello) ...
        clang: mean: 0.062 (+-0.001) secs  median: 0.062  range: 0.060-0.063  (noise: 2.354%)  (5 runs)   Relative: No baseline recorded yet
         emcc: mean: 0.166 (+-0.004) secs  median: 0.166  range: 0.159-0.171  (noise: 2.374%)  (5 runs)   Relative: 2.69 X slower
ok
[2/2] test_emcc_noop (test_benchmark.benchmark.test_emcc_noop) ...
        clang: mean: 0.044 (+-0.001) secs  median: 0.045  range: 0.042-0.045  (noise: 2.469%)  (5 runs)   Relative: No baseline recorded yet
         emcc: mean: 0.124 (+-0.003) secs  median: 0.124  range: 0.121-0.127  (noise: 2.169%)  (5 runs)   Relative: 2.82 X slower
ok
```
@sbc100 sbc100 force-pushed the toolchain_benchmark branch from 83196d5 to 5ac1ea2 Compare February 19, 2026 19:10
@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 19, 2026

I added a TODO to try to re-duplicate in the future.

@sbc100 sbc100 disabled auto-merge February 19, 2026 21:45
@sbc100 sbc100 merged commit e5d848b into emscripten-core:main Feb 19, 2026
36 checks passed
@sbc100 sbc100 deleted the toolchain_benchmark branch February 19, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments