Skip to content

Commit ec5332c

Browse files
committed
bench: add cephes and update existing as per conventions
--- 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 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: passed - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent ce032a9 commit ec5332c

File tree

8 files changed

+568
-18
lines changed

8 files changed

+568
-18
lines changed

lib/node_modules/@stdlib/math/base/special/exp10f/benchmark/benchmark.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26-
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2726
var pkg = require( './../package.json' ).name;
2827
var exp10f = require( './../lib' );
2928

@@ -35,10 +34,13 @@ bench( pkg, function benchmark( b ) {
3534
var y;
3635
var i;
3736

37+
x = uniform( 100, -10.0, 10.0, {
38+
'dtype': 'float32'
39+
});
40+
3841
b.tic();
3942
for ( i = 0; i < b.iterations; i++ ) {
40-
x = float64ToFloat32( ( randu() * 100.0 ) - 50.0 );
41-
y = exp10f( x );
43+
y = exp10f( x[ i%x.length ] );
4244
if ( isnanf( y ) ) {
4345
b.fail( 'should not return NaN' );
4446
}

lib/node_modules/@stdlib/math/base/special/exp10f/benchmark/benchmark.native.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27-
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2827
var tryRequire = require( '@stdlib/utils/try-require' );
2928
var pkg = require( './../package.json' ).name;
3029

@@ -39,15 +38,18 @@ var opts = {
3938

4039
// MAIN //
4140

42-
bench( pkg + '::native', opts, function benchmark( b ) {
41+
bench( pkg+'::native', opts, function benchmark( b ) {
4342
var x;
4443
var y;
4544
var i;
4645

46+
x = uniform( 100, -10.0, 10.0, {
47+
'dtype': 'float32'
48+
});
49+
4750
b.tic();
4851
for ( i = 0; i < b.iterations; i++ ) {
49-
x = float64ToFloat32( ( randu() * 100.0 ) - 50.0 );
50-
y = exp10f( x );
52+
y = exp10f( x[ i%x.length ] );
5153
if ( isnanf( y ) ) {
5254
b.fail( 'should not return NaN' );
5355
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2025 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
ifndef VERBOSE
22+
QUIET := @
23+
else
24+
QUIET :=
25+
endif
26+
27+
# Determine the OS ([1][1], [2][2]).
28+
#
29+
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
30+
# [2]: http://stackoverflow.com/a/27776822/2225624
31+
OS ?= $(shell uname)
32+
ifneq (, $(findstring MINGW,$(OS)))
33+
OS := WINNT
34+
else
35+
ifneq (, $(findstring MSYS,$(OS)))
36+
OS := WINNT
37+
else
38+
ifneq (, $(findstring CYGWIN,$(OS)))
39+
OS := WINNT
40+
else
41+
ifneq (, $(findstring Windows_NT,$(OS)))
42+
OS := WINNT
43+
endif
44+
endif
45+
endif
46+
endif
47+
48+
# Define the program used for compiling C source files:
49+
ifdef C_COMPILER
50+
CC := $(C_COMPILER)
51+
else
52+
CC := gcc
53+
endif
54+
55+
# Define the command-line options when compiling C files:
56+
CFLAGS ?= \
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
61+
62+
# Determine whether to generate position independent code ([1][1], [2][2]).
63+
#
64+
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65+
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
66+
ifeq ($(OS), WINNT)
67+
fPIC ?=
68+
else
69+
fPIC ?= -fPIC
70+
endif
71+
72+
# List of C targets:
73+
c_targets := benchmark.out
74+
75+
76+
# RULES #
77+
78+
#/
79+
# Compiles C source files.
80+
#
81+
# @param {string} [C_COMPILER] - C compiler
82+
# @param {string} [CFLAGS] - C compiler flags
83+
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
84+
#
85+
# @example
86+
# make
87+
#
88+
# @example
89+
# make all
90+
#/
91+
all: $(c_targets)
92+
93+
.PHONY: all
94+
95+
#/
96+
# Compiles C source files.
97+
#
98+
# @private
99+
# @param {string} CC - C compiler
100+
# @param {string} CFLAGS - C compiler flags
101+
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
102+
#/
103+
$(c_targets): %.out: %.c
104+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm
105+
106+
#/
107+
# Runs compiled benchmarks.
108+
#
109+
# @example
110+
# make run
111+
#/
112+
run: $(c_targets)
113+
$(QUIET) ./$<
114+
115+
.PHONY: run
116+
117+
#/
118+
# Removes generated files.
119+
#
120+
# @example
121+
# make clean
122+
#/
123+
clean:
124+
$(QUIET) -rm -f *.o *.out
125+
126+
.PHONY: clean
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <stdlib.h>
20+
#include <stdio.h>
21+
#include <math.h>
22+
#include <time.h>
23+
#include <sys/time.h>
24+
25+
#define NAME "exp10f"
26+
#define ITERATIONS 1000000
27+
#define REPEATS 3
28+
29+
/**
30+
* Prints the TAP version.
31+
*/
32+
static void print_version( void ) {
33+
printf( "TAP version 13\n" );
34+
}
35+
36+
/**
37+
* Prints the TAP summary.
38+
*
39+
* @param total total number of tests
40+
* @param passing total number of passing tests
41+
*/
42+
static void print_summary( int total, int passing ) {
43+
printf( "#\n" );
44+
printf( "1..%d\n", total ); // TAP plan
45+
printf( "# total %d\n", total );
46+
printf( "# pass %d\n", passing );
47+
printf( "#\n" );
48+
printf( "# ok\n" );
49+
}
50+
51+
/**
52+
* Prints benchmark results.
53+
*
54+
* @param elapsed elapsed time in seconds
55+
*/
56+
static void print_results( double elapsed ) {
57+
double rate = (double)ITERATIONS / elapsed;
58+
printf( " ---\n" );
59+
printf( " iterations: %d\n", ITERATIONS );
60+
printf( " elapsed: %0.9f\n", elapsed );
61+
printf( " rate: %0.9f\n", rate );
62+
printf( " ...\n" );
63+
}
64+
65+
/**
66+
* Returns a clock time.
67+
*
68+
* @return clock time
69+
*/
70+
static double tic( void ) {
71+
struct timeval now;
72+
gettimeofday( &now, NULL );
73+
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
74+
}
75+
76+
/**
77+
* Generates a random number on the interval [min,max).
78+
*
79+
* @param min minimum value (inclusive)
80+
* @param max maximum value (exclusive)
81+
* @return random number
82+
*/
83+
static float random_uniform( const float min, const float max ) {
84+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
85+
return min + ( v*(max-min) );
86+
}
87+
88+
/**
89+
* Runs a benchmark.
90+
*
91+
* @return elapsed time in seconds
92+
*/
93+
static double benchmark( void ) {
94+
float x[ 100 ];
95+
double elapsed;
96+
double t;
97+
float y;
98+
int i;
99+
100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = random_uniform( -10.0f, 10.0f );
102+
}
103+
104+
t = tic();
105+
for ( i = 0; i < ITERATIONS; i++ ) {
106+
y = exp10f( x[ i%100 ] );
107+
if ( y != y ) {
108+
printf( "should not return NaN\n" );
109+
break;
110+
}
111+
}
112+
elapsed = tic() - t;
113+
if ( y != y ) {
114+
printf( "should not return NaN\n" );
115+
}
116+
return elapsed;
117+
}
118+
119+
/**
120+
* Main execution sequence.
121+
*/
122+
int main( void ) {
123+
double elapsed;
124+
int i;
125+
126+
// Use the current time to seed the random number generator:
127+
srand( time( NULL ) );
128+
129+
print_version();
130+
for ( i = 0; i < REPEATS; i++ ) {
131+
printf( "# c::%s\n", NAME );
132+
elapsed = benchmark();
133+
print_results( elapsed );
134+
printf( "ok %d benchmark finished\n", i+1 );
135+
}
136+
print_summary( REPEATS, REPEATS );
137+
}

0 commit comments

Comments
 (0)