Skip to content

Commit 281b664

Browse files
committed
added makefile inside native folder
1 parent df17998 commit 281b664

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

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

Whitespace-only changes.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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/math/base/special/cosc.h"
20+
#include <stdlib.h>
21+
#include <stdio.h>
22+
#include <math.h>
23+
#include <time.h>
24+
#include <sys/time.h>
25+
26+
#define NAME "cosc"
27+
#define ITERATIONS 1000000
28+
#define REPEATS 3
29+
30+
/**
31+
* Prints the TAP version.
32+
*/
33+
static void print_version( void ) {
34+
printf( "TAP version 13\n" );
35+
}
36+
37+
/**
38+
* Prints the TAP summary.
39+
*
40+
* @param total total number of tests
41+
* @param passing total number of passing tests
42+
*/
43+
static void print_summary( int total, int passing ) {
44+
printf( "#\n" );
45+
printf( "1..%d\n", total ); // TAP plan
46+
printf( "# total %d\n", total );
47+
printf( "# pass %d\n", passing );
48+
printf( "#\n" );
49+
printf( "# ok\n" );
50+
}
51+
52+
/**
53+
* Prints benchmarks results.
54+
*
55+
* @param elapsed elapsed time in seconds
56+
*/
57+
static void print_results( double elapsed ) {
58+
double rate = (double)ITERATIONS / elapsed;
59+
printf( " ---\n" );
60+
printf( " iterations: %d\n", ITERATIONS );
61+
printf( " elapsed: %0.9f\n", elapsed );
62+
printf( " rate: %0.9f\n", rate );
63+
printf( " ...\n" );
64+
}
65+
66+
/**
67+
* Returns a clock time.
68+
*
69+
* @return clock time
70+
*/
71+
static double tic( void ) {
72+
struct timeval now;
73+
gettimeofday( &now, NULL );
74+
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
75+
}
76+
77+
/**
78+
* Generates a random number on the interval [0,1).
79+
*
80+
* @return random number
81+
*/
82+
static double rand_double( void ) {
83+
int r = rand();
84+
return (double)r / ( (double)RAND_MAX + 1.0 );
85+
}
86+
87+
/**
88+
* Runs a benchmark.
89+
*
90+
* @return elapsed time in seconds
91+
*/
92+
static double benchmark( void ) {
93+
double elapsed;
94+
double x;
95+
double y;
96+
double t;
97+
int i;
98+
99+
t = tic();
100+
for ( i = 0; i < ITERATIONS; i++ ) {
101+
x = ( 2.0 * rand_double() ) - 2.0;
102+
y = stdlib_base_cosc( x );
103+
if ( y != y ) {
104+
printf( "should not return NaN\n" );
105+
break;
106+
}
107+
}
108+
elapsed = tic() - t;
109+
if ( y != y ) {
110+
printf( "should not return NaN\n" );
111+
}
112+
return elapsed;
113+
}
114+
115+
/**
116+
* Main execution sequence.
117+
*/
118+
int main( void ) {
119+
double elapsed;
120+
int i;
121+
122+
// Use the current time to seed the random number generator:
123+
srand( time( NULL ) );
124+
125+
print_version();
126+
for ( i = 0; i < REPEATS; i++ ) {
127+
printf( "# c::native::%s\n", NAME );
128+
elapsed = benchmark();
129+
print_results( elapsed );
130+
printf( "ok %d benchmark finished\n", i+1 );
131+
}
132+
print_summary( REPEATS, REPEATS );
133+
}

0 commit comments

Comments
 (0)