From c73cdf4e3b2495a9a61a1429bf433460a02bea04 Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Mon, 8 Dec 2025 18:23:39 +0530 Subject: [PATCH 1/8] bench: refactor to use dynamic memory allocation in 'blas/base/cscal' --- .../base/ccopy/benchmark/c/benchmark.length.c | 16 ++++++++++++---- .../base/cscal/benchmark/c/benchmark.length.c | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c index bb78a5ab0ff0..83533ae2aef3 100644 --- a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c @@ -96,11 +96,13 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * 2 * sizeof( float ) ); + y = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -119,6 +121,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } @@ -131,11 +135,13 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * 2 * sizeof( float ) ); + y = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -154,6 +160,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c index d8304dd48453..ee2163e5b25e 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c @@ -97,12 +97,13 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { stdlib_complex64_t alpha; - float x[ len*2 ]; + float *x; double elapsed; double t; int i; alpha = stdlib_complex64( 1.0f, 0.0f ); + x = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len*2; i += 2 ) { x[ i ] = ( rand_float()*2.0f ) - 1.0f; x[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; @@ -119,6 +120,7 @@ static double benchmark1( int iterations, int len ) { if ( x[ 0 ] != x[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } @@ -131,12 +133,13 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { stdlib_complex64_t alpha; - float x[ len*2 ]; + float *x; double elapsed; double t; int i; alpha = stdlib_complex64( 1.0f, 0.0f ); + x = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len*2; i += 2 ) { x[ i ] = ( rand_float()*2.0f ) - 1.0f; x[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; @@ -153,6 +156,7 @@ static double benchmark2( int iterations, int len ) { if ( x[ 0 ] != x[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } From 9125c9c2ad97f1b875413af6a594b831bce940f8 Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Mon, 8 Dec 2025 18:39:27 +0530 Subject: [PATCH 2/8] bench: refactor to use dynamic memory allocation in 'blas/base/csrot' --- .../base/csrot/benchmark/c/benchmark.length.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c index f2612a68663a..684b13a92962 100644 --- a/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c @@ -96,11 +96,13 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + + float *y; double t; int i; - + x = (float *)( malloc( len * 2 * sizeof( float ) ) ); + y = (float *)( malloc( len * 2 * sizeof( float ) ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -119,6 +121,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } @@ -131,11 +135,12 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; - + x = (float *)( malloc( len * 2 * sizeof( float ) ) ); + y = (float *)( malloc( len * 2 * sizeof( float ) ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -154,6 +159,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } From 4782640c765f8b33145e6af4f7752e369767623c Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Tue, 9 Dec 2025 19:00:39 +0530 Subject: [PATCH 3/8] bench: refactor to use dynamic memory allocation in 'blas/base/ccopy' --- .../base/ccopy/benchmark/c/benchmark.length.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c index bb78a5ab0ff0..69e91189d3f3 100644 --- a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c @@ -96,11 +96,12 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; - + x=(float*)malloc(len*2*sizeof(float)); + y=(float*)malloc(len*2*sizeof(float)); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -119,6 +120,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } @@ -131,11 +134,12 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; - + x=(float*)malloc(len*2*sizeof(float)); + y=(float*)malloc(len*2*sizeof(float)); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -154,6 +158,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free(x); + free(y); return elapsed; } From 7d021b926c988fdb6fd6e4ea9aba83622c07127d Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Wed, 10 Dec 2025 10:09:27 +0530 Subject: [PATCH 4/8] fixed whitespace convention --- .../blas/base/ccopy/benchmark/c/benchmark.length.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c index 69e91189d3f3..7b06d7c93b1a 100644 --- a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c @@ -100,8 +100,8 @@ static double benchmark1( int iterations, int len ) { float *y; double t; int i; - x=(float*)malloc(len*2*sizeof(float)); - y=(float*)malloc(len*2*sizeof(float)); + x = (float *) malloc( len * 2 * sizeof( float ) ); + y = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -138,8 +138,8 @@ static double benchmark2( int iterations, int len ) { float *y; double t; int i; - x=(float*)malloc(len*2*sizeof(float)); - y=(float*)malloc(len*2*sizeof(float)); + x = (float *) malloc( len * 2 * sizeof( float ) ); + y = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; From 9ae9916b46d2d3508a3f6b2fd3d749f2c65da96e Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Wed, 10 Dec 2025 13:46:00 +0530 Subject: [PATCH 5/8] bench: refactor to use dynamic memory allocation in 'blas/base/csrot' --- .../base/csrot/benchmark/c/benchmark.length.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c index f2612a68663a..208481e2dcd1 100644 --- a/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c @@ -96,11 +96,13 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * 2 * sizeof( float ) ); + y = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -119,6 +121,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } @@ -131,11 +135,12 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len*2 ]; - float y[ len*2 ]; + float *x; + float *y; double t; int i; - + x = (float *) malloc( len * 2 * sizeof( float ) ); + y = (float *) malloc( len * 2 * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; @@ -154,6 +159,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } From 7ab3e9a4edb6868165403de530dabbea1841e16c Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Wed, 10 Dec 2025 18:25:26 +0530 Subject: [PATCH 6/8] bench: refactor to use dynamic memory allocation in 'blas/base/csrot' --- .../blas/base/csrot/benchmark/c/benchmark.length.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c index 69260faed8e6..600a18601d2c 100644 --- a/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/csrot/benchmark/c/benchmark.length.c @@ -97,21 +97,12 @@ static float rand_float( void ) { static double benchmark1( int iterations, int len ) { double elapsed; float *x; -<<<<<<< HEAD float *y; double t; int i; x = (float *) malloc( len * 2 * sizeof( float ) ); y = (float *) malloc( len * 2 * sizeof( float ) ); -======= - - float *y; - double t; - int i; - x = (float *)( malloc( len * 2 * sizeof( float ) ) ); - y = (float *)( malloc( len * 2 * sizeof( float ) ) ); ->>>>>>> 9125c9c2ad97f1b875413af6a594b831bce940f8 for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; From b6278b75ad78484999cb8cab495da7c9856d71df Mon Sep 17 00:00:00 2001 From: Ishwar <142937211+ishwarthecodddr@users.noreply.github.com> Date: Wed, 10 Dec 2025 18:29:45 +0530 Subject: [PATCH 7/8] Delete lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c Signed-off-by: Ishwar <142937211+ishwarthecodddr@users.noreply.github.com> --- .../base/ccopy/benchmark/c/benchmark.length.c | 193 ------------------ 1 file changed, 193 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c diff --git a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c deleted file mode 100644 index bfc36c487e51..000000000000 --- a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c +++ /dev/null @@ -1,193 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/base/ccopy.h" -#include -#include -#include -#include -#include - -#define NAME "ccopy" -#define ITERATIONS 10000000 -#define REPEATS 3 -#define MIN 1 -#define MAX 6 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param iterations number of iterations -* @param elapsed elapsed time in seconds -*/ -static void print_results( int iterations, double elapsed ) { - double rate = (double)iterations / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", iterations ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark1( int iterations, int len ) { - double elapsed; - float *x; - float *y; - double t; - int i; - x = (float *) malloc( len * 2 * sizeof( float ) ); - y = (float *) malloc( len * 2 * sizeof( float ) ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; - x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; - y[ i ] = 0.0f; - y[ i+1 ] = 0.0f; - } - t = tic(); - for ( i = 0; i < iterations; i++ ) { - c_ccopy( len, (void *)x, 1, (void *)y, 1 ); - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - } - free( x ); - free( y ); - return elapsed; -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark2( int iterations, int len ) { - double elapsed; - float *x; - float *y; - double t; - int i; -<<<<<<< HEAD -======= - ->>>>>>> 9125c9c2ad97f1b875413af6a594b831bce940f8 - x = (float *) malloc( len * 2 * sizeof( float ) ); - y = (float *) malloc( len * 2 * sizeof( float ) ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; - x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; - y[ i ] = 0.0f; - y[ i+1 ] = 0.0f; - } - t = tic(); - for ( i = 0; i < iterations; i++ ) { - c_ccopy_ndarray( len, (void *)x, 1, 0, (void *)y, 1, 0 ); - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - } -<<<<<<< HEAD - free(x); - free(y); -======= - free( x ); - free( y ); ->>>>>>> 9125c9c2ad97f1b875413af6a594b831bce940f8 -rsion(); - count = 0; - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark1( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:ndarray:len=%d\n", NAME, len ); - elapsed = benchmark2( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - print_summary( count, count ); -} From 6efe573c8553f067ccd0e76a40dea9a068d1e74b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 15 Dec 2025 20:05:03 -0800 Subject: [PATCH 8/8] Discard changes to lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c --- .../base/ccopy/benchmark/c/benchmark.length.c | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c diff --git a/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..bb78a5ab0ff0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ccopy/benchmark/c/benchmark.length.c @@ -0,0 +1,195 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ccopy.h" +#include +#include +#include +#include +#include + +#define NAME "ccopy" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float x[ len*2 ]; + float y[ len*2 ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; + y[ i ] = 0.0f; + y[ i+1 ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_ccopy( len, (void *)x, 1, (void *)y, 1 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len*2 ]; + float y[ len*2 ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; + y[ i ] = 0.0f; + y[ i+1 ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_ccopy_ndarray( len, (void *)x, 1, 0, (void *)y, 1, 0 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +}