Skip to content

Commit ad6fc96

Browse files
committed
Add benchmark for retrieving ndarray subscript index modes
1 parent c7801ec commit ad6fc96

File tree

1 file changed

+51
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/ctor/benchmark/c

1 file changed

+51
-0
lines changed

Diff for: lib/node_modules/@stdlib/ndarray/ctor/benchmark/c/benchmark.c

+51
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,50 @@ double benchmark62() {
30623062
return elapsed;
30633063
}
30643064

3065+
/**
3066+
* Runs a benchmark.
3067+
*
3068+
* @return elapsed time in seconds
3069+
*/
3070+
double benchmark63() {
3071+
enum STDLIB_NDARRAY_INDEX_MODE *v;
3072+
double elapsed;
3073+
double t;
3074+
int i;
3075+
3076+
uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 };
3077+
int64_t ndims = 2;
3078+
int64_t shape[] = { 3, 2 };
3079+
int64_t strides[] = { 2, 1 };
3080+
int64_t offset = 0;
3081+
int64_t nsubmodes = 1;
3082+
enum STDLIB_NDARRAY_INDEX_MODE submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
3083+
3084+
struct ndarray *arr = stdlib_ndarray_constructor( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes );
3085+
if ( arr == NULL ) {
3086+
printf( "unable to allocate memory\n" );
3087+
exit( 1 );
3088+
}
3089+
3090+
t = tic();
3091+
for ( i = 0; i < ITERATIONS; i++ ) {
3092+
// NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless.
3093+
v = stdlib_ndarray_submodes( arr );
3094+
if ( v[ 0 ] != submodes[ 0 ] ) {
3095+
printf( "unexpected result\n" );
3096+
break;
3097+
}
3098+
}
3099+
elapsed = tic() - t;
3100+
3101+
if ( v[ 0 ] != submodes[ 0 ] ) {
3102+
printf( "unexpected result\n" );
3103+
}
3104+
free( arr );
3105+
3106+
return elapsed;
3107+
}
3108+
30653109
/**
30663110
* Main execution sequence.
30673111
*/
@@ -3510,5 +3554,12 @@ int main( void ) {
35103554
print_results( elapsed );
35113555
printf( "ok %d benchmark finished\n", count );
35123556
}
3557+
for ( i = 0; i < REPEATS; i++ ) {
3558+
count += 1;
3559+
printf( "# c::native::%s::get:submodes\n", NAME );
3560+
elapsed = benchmark63();
3561+
print_results( elapsed );
3562+
printf( "ok %d benchmark finished\n", count );
3563+
}
35133564
print_summary( count, count );
35143565
}

0 commit comments

Comments
 (0)