Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions tools/snippets/benchmark/c/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static void print_version( void );
static void print_summary( int total, int passing );
static void print_results( double elapsed );
static double tic( void );
static float rand_float( void );
static double rand_double( void );
static float random_uniformf( const float min, const float max );
static double random_uniform( const double min, const double max );
static double benchmark( void );

/**
Expand Down Expand Up @@ -85,23 +85,27 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniformf( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*(max-min) );
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}

/**
Expand Down
28 changes: 16 additions & 12 deletions tools/snippets/benchmark/c/cephes/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static void print_version( void );
static void print_summary( int total, int passing );
static void print_results( double elapsed );
static double tic( void );
static float rand_float( void );
static double rand_double( void );
static float random_uniformf( const float min, const float max );
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The float version we use is also called random_uniform. I'm not sure what we can do here so it is also not confusing to contributors following snippets for benchmark file references.

static double random_uniform( const double min, const double max );
static double benchmark( void );


Expand Down Expand Up @@ -91,23 +91,27 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1].
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniformf( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*(max-min) );
}

/**
* Generates a random number on the interval [0,1].
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}

/**
Expand Down
28 changes: 16 additions & 12 deletions tools/snippets/benchmark/c/native/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static void print_version( void );
static void print_summary( int total, int passing );
static void print_results( double elapsed );
static double tic( void );
static float rand_float( void );
static double rand_double( void );
static float random_uniformf( const float min, const float max );
static double random_uniform( const double min, const double max );
static double benchmark( void );

/**
Expand Down Expand Up @@ -86,23 +86,27 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1].
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniformf( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*(max-min) );
}

/**
* Generates a random number on the interval [0,1].
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}

/**
Expand Down
32 changes: 18 additions & 14 deletions tools/snippets/benchmark/c/native/benchmark.length.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static void print_version( void );
static void print_summary( int total, int passing );
static void print_results( int iterations, double elapsed );
static double tic( void );
static float rand_float( void );
static double rand_double( void );
static double benchmark( void );
static float random_uniformf( const float min, const float max );
static double random_uniform( const double min, const double max );
static double benchmark( int iterations, int len );

/**
* Prints the TAP version.
Expand Down Expand Up @@ -89,23 +89,27 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1].
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniformf( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*(max-min) );
}

/**
* Generates a random number on the interval [0,1].
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}

/**
Expand All @@ -124,7 +128,7 @@ static double benchmark( int iterations, int len ) {

x = (double *) malloc( len * sizeof( double ) );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*20000.0 ) - 10000.0;
x[ i ] = random_uniform( -10000.0, 10000.0 );
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
Expand Down
Loading