Skip to content

Commit 5cabb89

Browse files
committed
bench: align C benchmark with stdlib conventions
Co-authored-by: Claude <noreply@anthropic.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: 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 ---
1 parent f925b84 commit 5cabb89

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

  • lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c

lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <time.h>
2626
#include <sys/time.h>
2727

28-
#define NAME "logpdf"
28+
#define NAME "erlang-logpdf"
2929
#define ITERATIONS 1000000
3030
#define REPEATS 3
3131

@@ -44,7 +44,7 @@ static void print_version( void ) {
4444
*/
4545
static void print_summary( int total, int passing ) {
4646
printf( "#\n" );
47-
printf( "1..%d\n", total );
47+
printf( "1..%d\n", total ); // TAP plan
4848
printf( "# total %d\n", total );
4949
printf( "# pass %d\n", passing );
5050
printf( "#\n" );
@@ -54,15 +54,14 @@ static void print_summary( int total, int passing ) {
5454
/**
5555
* Prints benchmarks results.
5656
*
57-
* @param iterations number of iterations
58-
* @param elapsed elapsed time in seconds
57+
* @param elapsed elapsed time in seconds
5958
*/
60-
static void print_results( int iterations, double elapsed ) {
61-
double rate = (double)iterations / elapsed;
59+
static void print_results( double elapsed ) {
60+
double rate = (double)ITERATIONS / elapsed;
6261
printf( " ---\n" );
63-
printf( " iterations: %d\n", iterations );
64-
printf( " elapsed: %g\n", elapsed );
65-
printf( " rate: %g\n", rate );
62+
printf( " iterations: %d\n", ITERATIONS );
63+
printf( " elapsed: %0.9f\n", elapsed );
64+
printf( " rate: %0.9f\n", rate );
6665
printf( " ...\n" );
6766
}
6867

@@ -131,16 +130,15 @@ int main( void ) {
131130
double elapsed;
132131
int i;
133132

134-
// Initialize the pseudorandom number generator:
133+
// Use the current time to seed the random number generator:
135134
srand( time( NULL ) );
136135

137136
print_version();
138137
for ( i = 0; i < REPEATS; i++ ) {
139138
printf( "# c::%s\n", NAME );
140139
elapsed = benchmark();
141-
print_results( ITERATIONS, elapsed );
142-
printf( "ok %d benchmark finished\n", i + 1 );
140+
print_results( elapsed );
141+
printf( "ok %d benchmark finished\n", i+1 );
143142
}
144143
print_summary( REPEATS, REPEATS );
145-
return 0;
146144
}

0 commit comments

Comments
 (0)