Skip to content

Commit a15eebf

Browse files
committed
refactor: update benchmarks, test fixtures in math/base/special/round
--- 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: passed - 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: missing_dependencies - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent c61415f commit a15eebf

File tree

9 files changed

+155
-89
lines changed

9 files changed

+155
-89
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var randu = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pkg = require( './../package.json' ).name;
2727
var round = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = randu( 100, -500.0, 500.0 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1000.0 ) - 500.0;
40-
y = round( x );
41+
y = round( x[ i % x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}
@@ -55,10 +56,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
5556
var y;
5657
var i;
5758

59+
x = randu( 100, -500.0, 500.0 );
60+
5861
b.tic();
5962
for ( i = 0; i < b.iterations; i++ ) {
60-
x = ( randu()*1000.0 ) - 500.0;
61-
y = Math.round( x ); // eslint-disable-line stdlib/no-builtin-math
63+
y = Math.round( x[ i % x.length ] ); // eslint-disable-line stdlib/no-builtin-math
6264
if ( isnan( y ) ) {
6365
b.fail( 'should not return NaN' );
6466
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var randu = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = randu( 100, -500.0, 500.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
4850
x = ( randu()*1000.0 ) - 500.0;
49-
y = round( x );
51+
y = round( x[ i % x.length ] );
5052
if ( isnan( y ) ) {
5153
b.fail( 'should not return NaN' );
5254
}

lib/node_modules/@stdlib/math/base/special/round/benchmark/c/Makefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2018 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616
# limitations under the License.
1717
#/
1818

19-
2019
# VARIABLES #
2120

2221
ifndef VERBOSE
@@ -70,18 +69,34 @@ else
7069
fPIC ?= -fPIC
7170
endif
7271

72+
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73+
INCLUDE ?=
74+
75+
# List of source files:
76+
SOURCE_FILES ?=
77+
78+
# List of libraries (e.g., `-lopenblas -lpthread`):
79+
LIBRARIES ?=
80+
81+
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82+
LIBPATH ?=
83+
7384
# List of C targets:
7485
c_targets := benchmark.out
7586

7687

7788
# RULES #
7889

7990
#/
80-
# Compiles C source files.
91+
# Compiles source files.
8192
#
82-
# @param {string} [C_COMPILER] - C compiler
83-
# @param {string} [CFLAGS] - C compiler flags
84-
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
93+
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94+
# @param {string} [CFLAGS] - C compiler options
95+
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97+
# @param {string} [SOURCE_FILES] - list of source files
98+
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
85100
#
86101
# @example
87102
# make
@@ -97,12 +112,16 @@ all: $(c_targets)
97112
# Compiles C source files.
98113
#
99114
# @private
100-
# @param {string} CC - C compiler
101-
# @param {string} CFLAGS - C compiler flags
102-
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
115+
# @param {string} CC - C compiler (e.g., `gcc`)
116+
# @param {string} CFLAGS - C compiler options
117+
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118+
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119+
# @param {string} SOURCE_FILES - list of source files
120+
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121+
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
103122
#/
104123
$(c_targets): %.out: %.c
105-
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
106125

107126
#/
108127
# Runs compiled benchmarks.

lib/node_modules/@stdlib/math/base/special/round/benchmark/c/benchmark.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -89,16 +89,19 @@ static double rand_double( void ) {
8989
* @return elapsed time in seconds
9090
*/
9191
static double benchmark( void ) {
92+
double x[ 100 ];
9293
double elapsed;
93-
double x;
9494
double y;
9595
double t;
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = ( 1000.0 * rand_double() ) - 500.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0*rand_double() ) - 500.0;
101-
y = round( x );
104+
y = round( x[ i % 100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

lib/node_modules/@stdlib/math/base/special/round/benchmark/c/cephes/Makefile

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2018 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -16,20 +16,15 @@
1616
# limitations under the License.
1717
#/
1818

19-
2019
# VARIABLES #
2120

2221
ifndef VERBOSE
2322
QUIET := @
23+
else
24+
QUIET :=
2425
endif
2526

26-
# Specify the path to Cephes:
27-
CEPHES ?=
28-
29-
# Specify a list of Cephes source files:
30-
CEPHES_SRC ?=
31-
32-
# Determine the OS:
27+
# Determine the OS ([1][1], [2][2]).
3328
#
3429
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
3530
# [2]: http://stackoverflow.com/a/27776822/2225624
@@ -42,6 +37,10 @@ ifneq (, $(findstring MSYS,$(OS)))
4237
else
4338
ifneq (, $(findstring CYGWIN,$(OS)))
4439
OS := WINNT
40+
else
41+
ifneq (, $(findstring Windows_NT,$(OS)))
42+
OS := WINNT
43+
endif
4544
endif
4645
endif
4746
endif
@@ -60,7 +59,7 @@ CFLAGS ?= \
6059
-Wall \
6160
-pedantic
6261

63-
# Determine whether to generate [position independent code][1]:
62+
# Determine whether to generate position independent code ([1][1], [2][2]).
6463
#
6564
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
6665
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
@@ -70,43 +69,77 @@ else
7069
fPIC ?= -fPIC
7170
endif
7271

72+
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73+
INCLUDE ?=
74+
75+
# List of source files:
76+
SOURCE_FILES ?=
77+
78+
# List of libraries (e.g., `-lopenblas -lpthread`):
79+
LIBRARIES ?=
80+
81+
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82+
LIBPATH ?=
83+
7384
# List of C targets:
7485
c_targets := benchmark.out
7586

7687

77-
# TARGETS #
88+
# RULES #
7889

79-
# Default target.
90+
#/
91+
# Compiles source files.
8092
#
81-
# This target is the default target.
82-
93+
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94+
# @param {string} [CFLAGS] - C compiler options
95+
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97+
# @param {string} [SOURCE_FILES] - list of source files
98+
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100+
#
101+
# @example
102+
# make
103+
#
104+
# @example
105+
# make all
106+
#/
83107
all: $(c_targets)
84108

85109
.PHONY: all
86110

87-
88-
# Compile C source.
111+
#/
112+
# Compiles C source files.
89113
#
90-
# This target compiles C source files.
91-
114+
# @private
115+
# @param {string} CC - C compiler (e.g., `gcc`)
116+
# @param {string} CFLAGS - C compiler options
117+
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118+
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119+
# @param {string} SOURCE_FILES - list of source files
120+
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121+
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122+
#/
92123
$(c_targets): %.out: %.c
93-
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $(CEPHES_SRC) $< -lm
94-
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
95125

96-
# Run a benchmark.
126+
#/
127+
# Runs compiled benchmarks.
97128
#
98-
# This target runs a benchmark.
99-
129+
# @example
130+
# make run
131+
#/
100132
run: $(c_targets)
101133
$(QUIET) ./$<
102134

103135
.PHONY: run
104136

105-
106-
# Perform clean-up.
137+
#/
138+
# Removes generated files.
107139
#
108-
# This target removes generated files.
109-
140+
# @example
141+
# make clean
142+
#/
110143
clean:
111144
$(QUIET) -rm -f *.o *.out
112145

lib/node_modules/@stdlib/math/base/special/round/benchmark/c/cephes/benchmark.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -94,16 +94,19 @@ static double rand_double( void ) {
9494
* @return elapsed time in seconds
9595
*/
9696
static double benchmark( void ) {
97+
double x[ 100 ];
9798
double elapsed;
98-
double x;
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = ( 1000.0 * rand_double() ) - 500.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = ( 1000.0*rand_double() ) - 500.0;
106-
y = round( x );
109+
y = round( x[ i % 100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

lib/node_modules/@stdlib/math/base/special/round/benchmark/c/native/benchmark.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -90,16 +90,20 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
9495
double x;
9596
double y;
9697
double t;
9798
int i;
9899

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 1000.0 * rand_double() ) - 500.0;
102+
}
103+
99104
t = tic();
100105
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 1000.0*rand_double() ) - 500.0;
102-
y = round( x );
106+
y = round( x[ i % 100 ] );
103107
if ( y != y ) {
104108
printf( "should not return NaN\n" );
105109
break;

0 commit comments

Comments
 (0)