Repository navigation
feat: add C benchmark harness to @stdlib/bench - #15400
0PrashantYadav0 wants to merge 8 commits into
Conversation
Signed-off-by: 0PrashantYadav0 <prashantyadav09783@gmail.com>
Signed-off-by: 0PrashantYadav0 <prashantyadav09783@gmail.com>
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown_pkg_readmes
status: na
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: passed
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
|
A few comments:
|
Signed-off-by: 0PrashantYadav0 <prashantyadav09783@gmail.com>
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown_pkg_readmes
status: passed
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
|
@kgryte All three done in d97a61e:
Also, per your inline comment, scalar and length-based benchmarks now use separate macros ( |
|
@anandkaranubc as discussed in office hours, |
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown_pkg_readmes
status: na
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
|
A side note, for single-precision benchmarks, authors would be casting the results: float r = (float)stdlib_bench_random_uniform( 1.0, 100.0 );There are 26 f32 benchmarks in Alternatively, a |
|
I think the simplest fix for this would be: static inline float stdlib_bench_rand_float32( void ) {
int r = rand();
return (float)( (double)r / ( (double)RAND_MAX + 1.0 ) );
} |
anandkaranubc
left a comment
There was a problem hiding this comment.
Other than the comments above, the PR looks solid! Thanks @0PrashantYadav0 for working on it 🚀
|
Thanks @anandkaranubc for review. |
|
@kgryte Will you please do a final review on this 🙏🏼 |
Resolves #13480, stdlib-js/metr-issue-tracker#1378.
Description
This pull request:
include/stdlib/bench.h) to@stdlib/bench, so C benchmark files no longer hand-roll TAP output, timing, PRNG helpers, and the length/iteration loop. The header depends only on the C standard library and emits the same TAP 13 output as the existing hand-written benchmarks.manifest.json(header-only, no dependencies), a C example, and aC APIssection to the@stdlib/benchREADME documenting every macro and helper.tools/scripts/compile_c_benchmarkto resolve the enclosing package name and pass it tomakeasBENCHMARK_NAME(overridable via the environment). ThenativeC benchmark Makefile snippet turns a non-emptyBENCHMARK_NAMEinto-DSTDLIB_BENCH_NAME="<package name>", so C benchmark names match the package-qualified names already used by JavaScript benchmarks (which readrequire( './../package.json' ).name). This addresses note 7 of the RFC: across files namedbenchmark.cthere are currently 1,327#define NAMElines but only 1,033 distinct values.blas/ext/base/zindex-of-truthy's C benchmark onto the harness as a pilot (200 → 105 lines). Its output name changes from# c::zindex_of_truthy:len=10to# c::@stdlib/blas/ext/base/zindex-of-truthy:len=10.Existing C benchmarks are untouched: their Makefiles ignore the extra
BENCHMARK_NAMEvariable, and in Makefiles which include the new block an emptyBENCHMARK_NAMEyields no-Dflag.Example
Differences from the RFC sketch
NAMEisSTDLIB_BENCH_NAME, so the build can define it without colliding with the unconditional#define NAMEin existing benchmark files.STDLIB_BENCH_EPILOGUEis not needed:STDLIB_BENCHgeneratesmain()around a wrapper function, so the TAP summary is printed automatically.STDLIB_BENCHMARK_FILL_STRIDED_ARRAY_FLOAT64isSTDLIB_BENCHMARK_FILL_ARRAY(the sketch's signature had no stride, and assignment is type-agnostic).STDLIB_BENCH_PREAMBLE( repeats, iterations )for scalar benchmarks,STDLIB_BENCH_PRINT_NAME()/STDLIB_BENCH_PRINT_NAME_F( fmt, ... )for the# c::line (note 6 of the RFC), andSTDLIB_BENCHMARK_UNUSED( x )so scalar benchmarks compile cleanly under-Wextra.-Iand nothing is linked or compiled.Verification
make examples-c EXAMPLES_FILTER=".*/@stdlib/bench/examples/c/.*"— passes.make benchmark-c BENCHMARKS_FILTER=".*/blas/ext/base/zindex-of-truthy/benchmark/c/.*"— 36 benchmarks,1..36,# ok, no compiler warnings (also clean under-Wextra).BENCHMARK_NAME=custom make benchmark-c ...— override respected; compiling without the define falls back to the in-file name.make benchmark-con an unmigrated benchmark (math/base/special/abs) — unchanged behavior.make lint-markdown-files FILES="lib/node_modules/@stdlib/bench/README.md"— passes.Related Issues
This pull request has the following related issues:
Questions
STDLIB_RUN_BENCHMARKkeeps the name from the RFC sketch, which does not follow theSTDLIB_BENCH_/STDLIB_BENCHMARK_prefix used by every other macro. It is documented as the one exception; happy to rename it toSTDLIB_BENCHMARK_RUNif preferred.tools/snippets/benchmark/c/benchmark.cis intentionally left unchanged so that adopting the harness for newly scaffolded packages can be decided separately.Other
shellcheckwithout a severity filter) reportsSC2153/SC2181ontools/scripts/compile_c_benchmark. Nineteen of the twenty-one findings pre-exist this change; the two new ones follow the file's existing pattern (name="${NAME}"andif [[ "$?" -ne 0 ]]).Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
AI assistant reviewed the design decisions and the resulting changes, and the verification steps listed above were run locally.
@stdlib-js/reviewers