Skip to content

Commit e171ceb

Browse files
committed
style: align complex/float64/base/identity with namespace conventions
Apply majority-pattern fixes from a drift sweep of `@stdlib/complex/float64/base`: - Remove vestigial `__stdlib__: {}` field from `package.json` (absent in 9/9 sibling packages = 100% conformance among non-`assert` siblings). - Add `benchmark/c/Makefile` (8/8 sibling native packages = 100% conformance). - Add `benchmark/c/benchmark.c` (8/8 sibling native packages = 100% conformance). - Add `benchmark/julia/REQUIRE` (8/8 sibling native packages = 100% conformance). - Add `benchmark/julia/benchmark.jl` (8/8 sibling native packages = 100% conformance). No public API or test changes; benchmark templates mirror `complex/float64/base/neg` (unary complex op of the same shape).
1 parent 8238153 commit e171ceb

5 files changed

Lines changed: 415 additions & 2 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2026 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+
20+
# VARIABLES #
21+
22+
ifndef VERBOSE
23+
QUIET := @
24+
else
25+
QUIET :=
26+
endif
27+
28+
# Determine the OS ([1][1], [2][2]).
29+
#
30+
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
31+
# [2]: http://stackoverflow.com/a/27776822/2225624
32+
OS ?= $(shell uname)
33+
ifneq (, $(findstring MINGW,$(OS)))
34+
OS := WINNT
35+
else
36+
ifneq (, $(findstring MSYS,$(OS)))
37+
OS := WINNT
38+
else
39+
ifneq (, $(findstring CYGWIN,$(OS)))
40+
OS := WINNT
41+
else
42+
ifneq (, $(findstring Windows_NT,$(OS)))
43+
OS := WINNT
44+
endif
45+
endif
46+
endif
47+
endif
48+
49+
# Define the program used for compiling C source files:
50+
ifdef C_COMPILER
51+
CC := $(C_COMPILER)
52+
else
53+
CC := gcc
54+
endif
55+
56+
# Define the command-line options when compiling C files:
57+
CFLAGS ?= \
58+
-std=c99 \
59+
-O3 \
60+
-Wall \
61+
-pedantic
62+
63+
# Determine whether to generate position independent code ([1][1], [2][2]).
64+
#
65+
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
66+
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
67+
ifeq ($(OS), WINNT)
68+
fPIC ?=
69+
else
70+
fPIC ?= -fPIC
71+
endif
72+
73+
# List of C targets:
74+
c_targets := benchmark.out
75+
76+
77+
# RULES #
78+
79+
#/
80+
# Compiles C source files.
81+
#
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
85+
#
86+
# @example
87+
# make
88+
#
89+
# @example
90+
# make all
91+
#/
92+
all: $(c_targets)
93+
94+
.PHONY: all
95+
96+
#/
97+
# Compiles C source files.
98+
#
99+
# @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
103+
#/
104+
$(c_targets): %.out: %.c
105+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm
106+
107+
#/
108+
# Runs compiled benchmarks.
109+
#
110+
# @example
111+
# make run
112+
#/
113+
run: $(c_targets)
114+
$(QUIET) ./$<
115+
116+
.PHONY: run
117+
118+
#/
119+
# Removes generated files.
120+
#
121+
# @example
122+
# make clean
123+
#/
124+
clean:
125+
$(QUIET) -rm -f *.o *.out
126+
127+
.PHONY: clean
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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+
/**
20+
* Benchmark complex number identity.
21+
*/
22+
23+
#include <stdlib.h>
24+
#include <stdio.h>
25+
#include <math.h>
26+
#include <complex.h>
27+
#include <sys/time.h>
28+
29+
#define NAME "identity"
30+
#define ITERATIONS 1000000
31+
#define REPEATS 3
32+
33+
/**
34+
* Prints the TAP version.
35+
*/
36+
static void print_version( void ) {
37+
printf( "TAP version 13\n" );
38+
}
39+
40+
/**
41+
* Prints the TAP summary.
42+
*
43+
* @param total total number of tests
44+
* @param passing total number of passing tests
45+
*/
46+
static void print_summary( int total, int passing ) {
47+
printf( "#\n" );
48+
printf( "1..%d\n", total ); // TAP plan
49+
printf( "# total %d\n", total );
50+
printf( "# pass %d\n", passing );
51+
printf( "#\n" );
52+
printf( "# ok\n" );
53+
}
54+
55+
/**
56+
* Prints benchmarks results.
57+
*
58+
* @param elapsed elapsed time in seconds
59+
*/
60+
static void print_results( double elapsed ) {
61+
double rate = (double)ITERATIONS / elapsed;
62+
printf( " ---\n" );
63+
printf( " iterations: %d\n", ITERATIONS );
64+
printf( " elapsed: %0.9f\n", elapsed );
65+
printf( " rate: %0.9f\n", rate );
66+
printf( " ...\n" );
67+
}
68+
69+
/**
70+
* Returns a clock time.
71+
*
72+
* @return clock time
73+
*/
74+
static double tic( void ) {
75+
struct timeval now;
76+
gettimeofday( &now, NULL );
77+
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
78+
}
79+
80+
/**
81+
* Generates a random number on the interval [0,1).
82+
*
83+
* @return random number
84+
*/
85+
static double rand_double( void ) {
86+
int r = rand();
87+
return (double)r / ( (double)RAND_MAX + 1.0 );
88+
}
89+
90+
/**
91+
* Runs a benchmark.
92+
*
93+
* @return elapsed time in seconds
94+
*/
95+
static double benchmark( void ) {
96+
double elapsed;
97+
double re;
98+
double im;
99+
double t;
100+
int i;
101+
102+
double complex z;
103+
double complex y;
104+
105+
t = tic();
106+
for ( i = 0; i < ITERATIONS; i++ ) {
107+
re = ( 1000.0*rand_double() ) - 500.0;
108+
im = ( 1000.0*rand_double() ) - 500.0;
109+
z = re + im*I;
110+
y = creal(z) + ( cimag(z) )*I;
111+
if ( y != y ) {
112+
printf( "should not return NaN\n" );
113+
break;
114+
}
115+
}
116+
elapsed = tic() - t;
117+
if ( y != y ) {
118+
printf( "should not return NaN\n" );
119+
}
120+
return elapsed;
121+
}
122+
123+
/**
124+
* Main execution sequence.
125+
*/
126+
int main( void ) {
127+
double elapsed;
128+
int i;
129+
130+
// Use the current time to seed the random number generator:
131+
srand( time( NULL ) );
132+
133+
print_version();
134+
for ( i = 0; i < REPEATS; i++ ) {
135+
printf( "# c::%s\n", NAME );
136+
elapsed = benchmark();
137+
print_results( elapsed );
138+
printf( "ok %d benchmark finished\n", i+1 );
139+
}
140+
print_summary( REPEATS, REPEATS );
141+
}
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

0 commit comments

Comments
 (0)