Skip to content

Commit 26cd960

Browse files
committed
bench: move PRNG out of loop and update Makefiles
--- 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: 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: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent b0f11b1 commit 26cd960

File tree

3 files changed

+68
-44
lines changed

3 files changed

+68
-44
lines changed

lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/Makefile

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,21 @@ LIBRARIES ?=
8282
LIBPATH ?=
8383

8484
# List of C targets:
85-
c_targets := benchmark.out
85+
c_targets := TODO.out
8686

8787

8888
# RULES #
8989

9090
#/
91-
# Compiles source files.
91+
# Compiles C source files.
9292
#
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
93+
# @param {string} SOURCE_FILES - list of C source files
94+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`)
95+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`)
9896
# @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`)
97+
# @param {string} [C_COMPILER] - C compiler
98+
# @param {string} [CFLAGS] - C compiler flags
99+
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
100100
#
101101
# @example
102102
# make
@@ -112,13 +112,13 @@ all: $(c_targets)
112112
# Compiles C source files.
113113
#
114114
# @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`)
115+
# @param {string} SOURCE_FILES - list of C source files
116+
# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`)
117+
# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`)
118+
# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
119+
# @param {string} CC - C compiler
120+
# @param {string} CFLAGS - C compiler flags
121+
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
122122
#/
123123
$(c_targets): %.out: %.c
124124
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)

lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/Makefile

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
# limitations under the License.
1717
#/
1818

19-
2019
# VARIABLES #
2120

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

2627
# Specify the path to Boost:
2728
BOOST ?=
2829

29-
# Determine the OS:
30+
# Determine the OS ([1][1], [2][2]).
3031
#
3132
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
3233
# [2]: http://stackoverflow.com/a/27776822/2225624
@@ -39,6 +40,10 @@ ifneq (, $(findstring MSYS,$(OS)))
3940
else
4041
ifneq (, $(findstring CYGWIN,$(OS)))
4142
OS := WINNT
43+
else
44+
ifneq (, $(findstring Windows_NT,$(OS)))
45+
OS := WINNT
46+
endif
4247
endif
4348
endif
4449
endif
@@ -57,7 +62,7 @@ CXXFLAGS ?= \
5762
-Wall \
5863
-pedantic
5964

60-
# Determine whether to generate [position independent code][1]:
65+
# Determine whether to generate position independent code ([1][1], [2][2]).
6166
#
6267
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
6368
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
@@ -71,39 +76,55 @@ endif
7176
cxx_targets := benchmark.out
7277

7378

74-
# TARGETS #
79+
# RULES #
7580

76-
# Default target.
81+
#/
82+
# Compiles C++ source files.
7783
#
78-
# This target is the default target.
79-
84+
# @param {string} BOOST - Boost include directory
85+
# @param {string} [CXX_COMPILER] - C++ compiler
86+
# @param {string} [CXXFLAGS] - C++ compiler flags
87+
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
88+
#
89+
# @example
90+
# make
91+
#
92+
# @example
93+
# make all
94+
#/
8095
all: $(cxx_targets)
8196

8297
.PHONY: all
8398

84-
85-
# Compile C++ source.
99+
#/
100+
# Compiles C++ source files.
86101
#
87-
# This target compiles C++ source files.
88-
102+
# @private
103+
# @param {string} CXX - C++ compiler
104+
# @param {string} CXXFLAGS - C++ compiler flags
105+
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
106+
# @param {string} BOOST - Boost include directory
107+
#/
89108
$(cxx_targets): %.out: %.cpp $(BOOST)
90109
$(QUIET) $(CXX) $(CXXFLAGS) $(fPIC) -I $(BOOST) -o $@ $< -lm
91110

92-
93-
# Run a benchmark.
111+
#/
112+
# Runs compiled benchmarks.
94113
#
95-
# This target runs a benchmark.
96-
114+
# @example
115+
# make run
116+
#/
97117
run: $(cxx_targets)
98118
$(QUIET) ./$<
99119

100120
.PHONY: run
101121

102-
103-
# Perform clean-up.
122+
#/
123+
# Removes generated files.
104124
#
105-
# This target removes generated files.
106-
125+
# @example
126+
# make clean
127+
#/
107128
clean:
108129
$(QUIET) -rm -f *.o *.out
109130

lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/benchmark.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#include <time.h>
2323
#include <sys/time.h>
2424
#include <boost/random/mersenne_twister.hpp>
25-
#include <boost/random/uniform_real_distribution.hpp>
25+
#include <boost/random/uniform_int_distribution.hpp>
2626
#include <boost/math/special_functions/binomial.hpp>
2727

28-
using boost::random::uniform_real_distribution;
28+
using boost::random::uniform_int_distribution;
2929
using boost::random::mt19937;
3030

3131
#define NAME "binomcoeff"
@@ -86,24 +86,27 @@ double tic() {
8686
*/
8787
double benchmark() {
8888
double elapsed;
89+
int x[ 100 ];
90+
int y[ 100 ];
8991
double t;
90-
float x;
91-
float y;
9292
float z;
9393
int i;
9494

9595
// Define a new pseudorandom number generator:
9696
mt19937 rng;
9797

98-
// Define a uniform distribution for generating pseudorandom numbers as "floats" between a minimum value (inclusive) and a maximum value (exclusive):
99-
uniform_real_distribution<> randu1( 20.0f, 70.0f );
100-
uniform_real_distribution<> randu2( 0.0f, 20.0f );
98+
// Define a uniform distribution for generating pseudorandom numbers as "ints" between a minimum value and a maximum value, both inclusive:
99+
uniform_int_distribution<> randu1( 20, 70 );
100+
uniform_int_distribution<> randu2( 0, 20 );
101+
102+
for( i = 0; i < 100; i++ ) {
103+
x[ i ] = randu1( rng );
104+
y[ i ] = randu2( rng );
105+
}
101106

102107
t = tic();
103108
for ( i = 0; i < ITERATIONS; i++ ) {
104-
x = (int)randu1( rng );
105-
y = (int)randu2( rng );
106-
z = boost::math::binomial_coefficient<float>( x, y );
109+
z = boost::math::binomial_coefficient<float>( x[ i%100 ], y[ i%100 ] );
107110
if ( z != z ) {
108111
printf( "should not return NaN\n" );
109112
break;

0 commit comments

Comments
 (0)