Skip to content

Commit c548edd

Browse files
committed
bench: clean-up and add julia benchmarks
--- 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 adbae49 commit c548edd

File tree

5 files changed

+155
-9
lines changed

5 files changed

+155
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

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

37-
x = randu( 100, -5.0, 5.0 );
37+
x = uniform( 100, -5.0, 5.0 );
3838

3939
b.tic();
4040
for ( i = 0; i < b.iterations; i++ ) {
41-
y = sech( x[ i % x.length ] );
41+
y = sech( x[ i%x.length ] );
4242
if ( isnan( y ) ) {
4343
b.fail( 'should not return NaN' );
4444
}

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/array/uniform' );
25+
var uniform = 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,11 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = randu( 100, -5.0, 5.0 );
46+
x = uniform( 100, -5.0, 5.0 );
4747

4848
b.tic();
4949
for ( i = 0; i < b.iterations; i++ ) {
50-
y = sech( x[ i % x.length ] );
50+
y = sech( x[ i%x.length ] );
5151
if ( isnan( y ) ) {
5252
b.fail( 'should not return NaN' );
5353
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93-
double elapsed;
9493
double x[ 100 ];
94+
double elapsed;
9595
double y;
9696
double t;
9797
int i;
9898

9999
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( 10.0 * rand_double() ) - 5.0;
100+
x[ i ] = ( 10.0*rand_double() ) - 5.0;
101101
}
102102

103103
t = tic();
104104
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_sech( x[ i % 100 ] );
105+
y = stdlib_base_sech( x[ i%100 ] );
106106
if ( y != y ) {
107107
printf( "should not return NaN\n" );
108108
break;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
julia 1.5
2+
BenchmarkTools 0.5.0
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env julia
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2025 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
import BenchmarkTools
20+
using Printf
21+
22+
# Benchmark variables:
23+
name = "sech";
24+
repeats = 3;
25+
26+
"""
27+
print_version()
28+
29+
Prints the TAP version.
30+
31+
# Examples
32+
33+
``` julia
34+
julia> print_version()
35+
```
36+
"""
37+
function print_version()
38+
@printf( "TAP version 13\n" );
39+
end
40+
41+
"""
42+
print_summary( total, passing )
43+
44+
Print the benchmark summary.
45+
46+
# Arguments
47+
48+
* `total`: total number of tests
49+
* `passing`: number of passing tests
50+
51+
# Examples
52+
53+
``` julia
54+
julia> print_summary( 3, 3 )
55+
```
56+
"""
57+
function print_summary( total, passing )
58+
@printf( "#\n" );
59+
@printf( "1..%d\n", total ); # TAP plan
60+
@printf( "# total %d\n", total );
61+
@printf( "# pass %d\n", passing );
62+
@printf( "#\n" );
63+
@printf( "# ok\n" );
64+
end
65+
66+
"""
67+
print_results( iterations, elapsed )
68+
69+
Print benchmark results.
70+
71+
# Arguments
72+
73+
* `iterations`: number of iterations
74+
* `elapsed`: elapsed time (in seconds)
75+
76+
# Examples
77+
78+
``` julia
79+
julia> print_results( 1000000, 0.131009101868 )
80+
```
81+
"""
82+
function print_results( iterations, elapsed )
83+
rate = iterations / elapsed
84+
85+
@printf( " ---\n" );
86+
@printf( " iterations: %d\n", iterations );
87+
@printf( " elapsed: %0.9f\n", elapsed );
88+
@printf( " rate: %0.9f\n", rate );
89+
@printf( " ...\n" );
90+
end
91+
92+
"""
93+
benchmark()
94+
95+
Run a benchmark.
96+
97+
# Notes
98+
99+
* Benchmark results are returned as a two-element array: [ iterations, elapsed ].
100+
* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation.
101+
* The elapsed time is in seconds.
102+
103+
# Examples
104+
105+
``` julia
106+
julia> out = benchmark();
107+
```
108+
"""
109+
function benchmark()
110+
t = BenchmarkTools.@benchmark sech( (10.0*rand()) - 5.0 ) samples=1e6
111+
112+
# Compute the total "elapsed" time and convert from nanoseconds to seconds:
113+
s = sum( t.times ) / 1.0e9;
114+
115+
# Determine the number of "iterations":
116+
iter = length( t.times );
117+
118+
# Return the results:
119+
[ iter, s ];
120+
end
121+
122+
"""
123+
main()
124+
125+
Run benchmarks.
126+
127+
# Examples
128+
129+
``` julia
130+
julia> main();
131+
```
132+
"""
133+
function main()
134+
print_version();
135+
for i in 1:repeats
136+
@printf( "# julia::%s\n", name );
137+
results = benchmark();
138+
print_results( results[ 1 ], results[ 2 ] );
139+
@printf( "ok %d benchmark finished\n", i );
140+
end
141+
print_summary( repeats, repeats );
142+
end
143+
144+
main();

0 commit comments

Comments
 (0)