Skip to content

Commit d23d1ee

Browse files
committed
bench: refactor to use dynamic memory allocation at number/uint8/base/sub
--- 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: na - 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: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 53ce62b commit d23d1ee

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/node_modules/@stdlib/number/uint8/base/sub/benchmark/c/benchmark.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ static uint8_t sub( const uint8_t x, const uint8_t y ) {
9999
* @return elapsed time in seconds
100100
*/
101101
static double benchmark( void ) {
102-
uint8_t x[ 100 ];
102+
uint8_t *x;
103103
double elapsed;
104104
uint8_t y;
105105
double t;
106106
int i;
107107

108+
x = (uint8_t *) malloc( 100 * sizeof( uint8_t ) );
108109
for ( i = 0; i < 100; i++ ) {
109110
x[ i ] = (uint8_t)( 50.0*rand_double() ) + 10;
110111
}
@@ -121,6 +122,7 @@ static double benchmark( void ) {
121122
if ( y > 100 ) {
122123
printf( "unexpected result\n" );
123124
}
125+
free( x );
124126
return elapsed;
125127
}
126128

lib/node_modules/@stdlib/number/uint8/base/sub/benchmark/c/native/benchmark.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ static double rand_double( void ) {
9191
* @return elapsed time in seconds
9292
*/
9393
static double benchmark( void ) {
94-
uint8_t x[ 100 ];
94+
uint8_t *x;
9595
double elapsed;
9696
uint8_t y;
9797
double t;
9898
int i;
9999

100+
x = (uint8_t *) malloc( 100 * sizeof( uint8_t ) );
100101
for ( i = 0; i < 100; i++ ) {
101102
x[ i ] = (uint8_t)( 50.0*rand_double() ) + 10;
102103
}
@@ -113,6 +114,7 @@ static double benchmark( void ) {
113114
if ( y > 100 ) {
114115
printf( "unexpected value\n" );
115116
}
117+
free( x );
116118
return elapsed;
117119
}
118120

0 commit comments

Comments
 (0)