annotate src/libsndfile-1.0.27/tests/benchmark.c @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@40 3 **
Chris@40 4 ** This program is free software; you can redistribute it and/or modify
Chris@40 5 ** it under the terms of the GNU General Public License as published by
Chris@40 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@40 7 ** (at your option) any later version.
Chris@40 8 **
Chris@40 9 ** This program is distributed in the hope that it will be useful,
Chris@40 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@40 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@40 12 ** GNU General Public License for more details.
Chris@40 13 **
Chris@40 14 ** You should have received a copy of the GNU General Public License
Chris@40 15 ** along with this program; if not, write to the Free Software
Chris@40 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@40 17 */
Chris@40 18
Chris@40 19 #include "sfconfig.h"
Chris@40 20
Chris@40 21 #include <stdio.h>
Chris@40 22 #include <stdlib.h>
Chris@40 23
Chris@40 24 #if HAVE_UNISTD_H
Chris@40 25 #include <unistd.h>
Chris@40 26 #endif
Chris@40 27
Chris@40 28 #if (HAVE_DECL_S_IRGRP == 0)
Chris@40 29 #include <sf_unistd.h>
Chris@40 30 #endif
Chris@40 31
Chris@40 32 #include <string.h>
Chris@40 33 #include <math.h>
Chris@40 34 #include <time.h>
Chris@40 35 #include <fcntl.h>
Chris@40 36 #include <sys/stat.h>
Chris@40 37
Chris@40 38 #include <sndfile.h>
Chris@40 39
Chris@40 40 #ifndef M_PI
Chris@40 41 #define M_PI 3.14159265358979323846264338
Chris@40 42 #endif
Chris@40 43
Chris@40 44 /*
Chris@40 45 ** Neat solution to the Win32/OS2 binary file flage requirement.
Chris@40 46 ** If O_BINARY isn't already defined by the inclusion of the system
Chris@40 47 ** headers, set it to zero.
Chris@40 48 */
Chris@40 49 #ifndef O_BINARY
Chris@40 50 #define O_BINARY 0
Chris@40 51 #endif
Chris@40 52
Chris@40 53 #define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
Chris@40 54 #define READ_FLAGS (O_RDONLY | O_BINARY)
Chris@40 55
Chris@40 56 #if (defined (WIN32) || defined (_WIN32) || defined (__OS2__))
Chris@40 57 #define WRITE_PERMS 0777
Chris@40 58 #else
Chris@40 59 #define WRITE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP)
Chris@40 60 #endif
Chris@40 61
Chris@40 62 #define BUFFER_SIZE (1 << 18)
Chris@40 63 #define BLOCK_COUNT (30)
Chris@40 64 #define TEST_DURATION (5) /* 5 Seconds. */
Chris@40 65
Chris@40 66 typedef struct
Chris@40 67 { double write_rate ;
Chris@40 68 double read_rate ;
Chris@40 69 } PERF_STATS ;
Chris@40 70
Chris@40 71 static void *data = NULL ;
Chris@40 72
Chris@40 73 static void calc_raw_performance (PERF_STATS *stats) ;
Chris@40 74
Chris@40 75 static void calc_short_performance (int format, double read_rate, double write_rate) ;
Chris@40 76 static void calc_int_performance (int format, double read_rate, double write_rate) ;
Chris@40 77 static void calc_float_performance (int format, double read_rate, double write_rate) ;
Chris@40 78
Chris@40 79
Chris@40 80 static int cpu_is_big_endian (void) ;
Chris@40 81
Chris@40 82 static const char* get_subtype_str (int subtype) ;
Chris@40 83
Chris@40 84 int
Chris@40 85 main (int argc, char *argv [])
Chris@40 86 { PERF_STATS stats ;
Chris@40 87 char buffer [256] = "Benchmarking " ;
Chris@40 88 int format_major ;
Chris@40 89
Chris@40 90 if (! (data = malloc (BUFFER_SIZE * sizeof (double))))
Chris@40 91 { perror ("Error : malloc failed") ;
Chris@40 92 exit (1) ;
Chris@40 93 } ;
Chris@40 94
Chris@40 95 sf_command (NULL, SFC_GET_LIB_VERSION, buffer + strlen (buffer), sizeof (buffer) - strlen (buffer)) ;
Chris@40 96
Chris@40 97 puts (buffer) ;
Chris@40 98 memset (buffer, '-', strlen (buffer)) ;
Chris@40 99 puts (buffer) ;
Chris@40 100 printf ("Each test takes a little over %d seconds.\n\n", TEST_DURATION) ;
Chris@40 101
Chris@40 102 calc_raw_performance (&stats) ;
Chris@40 103
Chris@40 104 if (argc < 2 || strcmp ("--native-only", argv [1]) == 0)
Chris@40 105 { puts ("\nNative endian I/O :") ;
Chris@40 106 format_major = cpu_is_big_endian () ? SF_FORMAT_AIFF : SF_FORMAT_WAV ;
Chris@40 107
Chris@40 108 calc_short_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
Chris@40 109 calc_int_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
Chris@40 110 calc_int_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
Chris@40 111 calc_float_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
Chris@40 112 calc_float_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
Chris@40 113 calc_float_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
Chris@40 114 calc_float_performance (format_major | SF_FORMAT_FLOAT , stats.read_rate, stats.write_rate) ;
Chris@40 115 } ;
Chris@40 116
Chris@40 117 if (argc < 2 || strcmp ("--swap-only", argv [1]) == 0)
Chris@40 118 { puts ("\nEndian swapped I/O :") ;
Chris@40 119 format_major = cpu_is_big_endian () ? SF_FORMAT_WAV : SF_FORMAT_AIFF ;
Chris@40 120
Chris@40 121 calc_short_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
Chris@40 122 calc_int_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
Chris@40 123 calc_int_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
Chris@40 124 calc_float_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
Chris@40 125 calc_float_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
Chris@40 126 calc_float_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
Chris@40 127 calc_float_performance (format_major | SF_FORMAT_FLOAT , stats.read_rate, stats.write_rate) ;
Chris@40 128 } ;
Chris@40 129
Chris@40 130 puts ("") ;
Chris@40 131
Chris@40 132 free (data) ;
Chris@40 133
Chris@40 134 return 0 ;
Chris@40 135 } /* main */
Chris@40 136
Chris@40 137 /*==============================================================================
Chris@40 138 */
Chris@40 139
Chris@40 140 static void
Chris@40 141 calc_raw_performance (PERF_STATS *stats)
Chris@40 142 { clock_t start_clock, clock_time ;
Chris@40 143 int fd, k, byte_count, retval, op_count ;
Chris@40 144 const char *filename ;
Chris@40 145
Chris@40 146 filename = "benchmark.dat" ;
Chris@40 147
Chris@40 148 byte_count = BUFFER_SIZE * sizeof (short) ;
Chris@40 149
Chris@40 150 /* Collect write stats */
Chris@40 151 printf (" Raw write PCM_16 : ") ;
Chris@40 152 fflush (stdout) ;
Chris@40 153
Chris@40 154 clock_time = 0 ;
Chris@40 155 op_count = 0 ;
Chris@40 156 start_clock = clock () ;
Chris@40 157
Chris@40 158 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 159 { if ((fd = open (filename, WRITE_FLAGS, WRITE_PERMS)) < 0)
Chris@40 160 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 161 perror ("") ;
Chris@40 162 exit (1) ;
Chris@40 163 } ;
Chris@40 164
Chris@40 165 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 166 { if ((retval = write (fd, data, byte_count)) != byte_count)
Chris@40 167 { printf ("Error : write returned %d (should have been %d)\n", retval, byte_count) ;
Chris@40 168 exit (1) ;
Chris@40 169 } ;
Chris@40 170 } ;
Chris@40 171
Chris@40 172 close (fd) ;
Chris@40 173
Chris@40 174 clock_time = clock () - start_clock ;
Chris@40 175 op_count ++ ;
Chris@40 176 } ;
Chris@40 177
Chris@40 178 stats->write_rate = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
Chris@40 179 stats->write_rate *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 180 printf ("%10.0f samples per sec\n", stats->write_rate) ;
Chris@40 181
Chris@40 182 /* Collect read stats */
Chris@40 183 printf (" Raw read PCM_16 : ") ;
Chris@40 184 fflush (stdout) ;
Chris@40 185
Chris@40 186 clock_time = 0 ;
Chris@40 187 op_count = 0 ;
Chris@40 188 start_clock = clock () ;
Chris@40 189
Chris@40 190 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 191 { if ((fd = open (filename, READ_FLAGS)) < 0)
Chris@40 192 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 193 perror ("") ;
Chris@40 194 exit (1) ;
Chris@40 195 } ;
Chris@40 196
Chris@40 197 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 198 { if ((retval = read (fd, data, byte_count)) != byte_count)
Chris@40 199 { printf ("Error : write returned %d (should have been %d)\n", retval, byte_count) ;
Chris@40 200 exit (1) ;
Chris@40 201 } ;
Chris@40 202 } ;
Chris@40 203
Chris@40 204 close (fd) ;
Chris@40 205
Chris@40 206 clock_time = clock () - start_clock ;
Chris@40 207 op_count ++ ;
Chris@40 208 } ;
Chris@40 209
Chris@40 210 stats->read_rate = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
Chris@40 211 stats->read_rate *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 212 printf ("%10.0f samples per sec\n", stats->read_rate) ;
Chris@40 213
Chris@40 214 unlink (filename) ;
Chris@40 215 } /* calc_raw_performance */
Chris@40 216
Chris@40 217 /*------------------------------------------------------------------------------
Chris@40 218 */
Chris@40 219
Chris@40 220 static void
Chris@40 221 calc_short_performance (int format, double read_rate, double write_rate)
Chris@40 222 { SNDFILE *file ;
Chris@40 223 SF_INFO sfinfo ;
Chris@40 224 clock_t start_clock, clock_time ;
Chris@40 225 double performance ;
Chris@40 226 int k, item_count, retval, op_count ;
Chris@40 227 const char* subtype ;
Chris@40 228 short *short_data ;
Chris@40 229 const char *filename ;
Chris@40 230
Chris@40 231 filename = "benchmark.dat" ;
Chris@40 232 subtype = get_subtype_str (format & SF_FORMAT_SUBMASK) ;
Chris@40 233
Chris@40 234 short_data = data ;
Chris@40 235 item_count = BUFFER_SIZE ;
Chris@40 236 for (k = 0 ; k < item_count ; k++)
Chris@40 237 short_data [k] = 32700.0 * sin (2 * M_PI * k / 32000.0) ;
Chris@40 238
Chris@40 239 /* Collect write stats */
Chris@40 240 printf (" Write %-5s to %s : ", "short", subtype) ;
Chris@40 241 fflush (stdout) ;
Chris@40 242
Chris@40 243 sfinfo.channels = 1 ;
Chris@40 244 sfinfo.format = format ;
Chris@40 245 sfinfo.frames = 1 ;
Chris@40 246 sfinfo.samplerate = 32000 ;
Chris@40 247
Chris@40 248 clock_time = 0 ;
Chris@40 249 op_count = 0 ;
Chris@40 250 start_clock = clock () ;
Chris@40 251
Chris@40 252 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 253 { if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
Chris@40 254 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 255 perror ("") ;
Chris@40 256 exit (1) ;
Chris@40 257 } ;
Chris@40 258
Chris@40 259 /* Turn off the addition of a PEAK chunk. */
Chris@40 260 sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
Chris@40 261
Chris@40 262 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 263 { if ((retval = sf_write_short (file, short_data, item_count)) != item_count)
Chris@40 264 { printf ("Error : sf_write_short returned %d (should have been %d)\n", retval, item_count) ;
Chris@40 265 exit (1) ;
Chris@40 266 } ;
Chris@40 267 } ;
Chris@40 268
Chris@40 269 sf_close (file) ;
Chris@40 270
Chris@40 271 clock_time = clock () - start_clock ;
Chris@40 272 op_count ++ ;
Chris@40 273 } ;
Chris@40 274
Chris@40 275 performance = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
Chris@40 276 performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 277 printf ("%6.2f%% of raw write\n", 100.0 * performance / write_rate) ;
Chris@40 278
Chris@40 279 /* Collect read stats */
Chris@40 280 printf (" Read %-5s from %s : ", "short", subtype) ;
Chris@40 281 fflush (stdout) ;
Chris@40 282
Chris@40 283 clock_time = 0 ;
Chris@40 284 op_count = 0 ;
Chris@40 285 start_clock = clock () ;
Chris@40 286
Chris@40 287 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 288 { if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
Chris@40 289 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 290 perror ("") ;
Chris@40 291 exit (1) ;
Chris@40 292 } ;
Chris@40 293
Chris@40 294 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 295 { if ((retval = sf_read_short (file, short_data, item_count)) != item_count)
Chris@40 296 { printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ;
Chris@40 297 exit (1) ;
Chris@40 298 } ;
Chris@40 299 } ;
Chris@40 300
Chris@40 301 sf_close (file) ;
Chris@40 302
Chris@40 303 clock_time = clock () - start_clock ;
Chris@40 304 op_count ++ ;
Chris@40 305 } ;
Chris@40 306
Chris@40 307 performance = (1.0 * item_count) * BLOCK_COUNT * op_count ;
Chris@40 308 performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 309 printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ;
Chris@40 310
Chris@40 311 unlink (filename) ;
Chris@40 312
Chris@40 313 } /* calc_short_performance */
Chris@40 314 static void
Chris@40 315 calc_int_performance (int format, double read_rate, double write_rate)
Chris@40 316 { SNDFILE *file ;
Chris@40 317 SF_INFO sfinfo ;
Chris@40 318 clock_t start_clock, clock_time ;
Chris@40 319 double performance ;
Chris@40 320 int k, item_count, retval, op_count ;
Chris@40 321 const char* subtype ;
Chris@40 322 int *int_data ;
Chris@40 323 const char *filename ;
Chris@40 324
Chris@40 325 filename = "benchmark.dat" ;
Chris@40 326 subtype = get_subtype_str (format & SF_FORMAT_SUBMASK) ;
Chris@40 327
Chris@40 328 int_data = data ;
Chris@40 329 item_count = BUFFER_SIZE ;
Chris@40 330 for (k = 0 ; k < item_count ; k++)
Chris@40 331 int_data [k] = 32700.0 * (1 << 16) * sin (2 * M_PI * k / 32000.0) ;
Chris@40 332
Chris@40 333 /* Collect write stats */
Chris@40 334 printf (" Write %-5s to %s : ", "int", subtype) ;
Chris@40 335 fflush (stdout) ;
Chris@40 336
Chris@40 337 sfinfo.channels = 1 ;
Chris@40 338 sfinfo.format = format ;
Chris@40 339 sfinfo.frames = 1 ;
Chris@40 340 sfinfo.samplerate = 32000 ;
Chris@40 341
Chris@40 342 clock_time = 0 ;
Chris@40 343 op_count = 0 ;
Chris@40 344 start_clock = clock () ;
Chris@40 345
Chris@40 346 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 347 { if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
Chris@40 348 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 349 perror ("") ;
Chris@40 350 exit (1) ;
Chris@40 351 } ;
Chris@40 352
Chris@40 353 /* Turn off the addition of a PEAK chunk. */
Chris@40 354 sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
Chris@40 355
Chris@40 356 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 357 { if ((retval = sf_write_int (file, int_data, item_count)) != item_count)
Chris@40 358 { printf ("Error : sf_write_short returned %d (should have been %d)\n", retval, item_count) ;
Chris@40 359 exit (1) ;
Chris@40 360 } ;
Chris@40 361 } ;
Chris@40 362
Chris@40 363 sf_close (file) ;
Chris@40 364
Chris@40 365 clock_time = clock () - start_clock ;
Chris@40 366 op_count ++ ;
Chris@40 367 } ;
Chris@40 368
Chris@40 369 performance = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
Chris@40 370 performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 371 printf ("%6.2f%% of raw write\n", 100.0 * performance / write_rate) ;
Chris@40 372
Chris@40 373 /* Collect read stats */
Chris@40 374 printf (" Read %-5s from %s : ", "int", subtype) ;
Chris@40 375 fflush (stdout) ;
Chris@40 376
Chris@40 377 clock_time = 0 ;
Chris@40 378 op_count = 0 ;
Chris@40 379 start_clock = clock () ;
Chris@40 380
Chris@40 381 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 382 { if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
Chris@40 383 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 384 perror ("") ;
Chris@40 385 exit (1) ;
Chris@40 386 } ;
Chris@40 387
Chris@40 388 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 389 { if ((retval = sf_read_int (file, int_data, item_count)) != item_count)
Chris@40 390 { printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ;
Chris@40 391 exit (1) ;
Chris@40 392 } ;
Chris@40 393 } ;
Chris@40 394
Chris@40 395 sf_close (file) ;
Chris@40 396
Chris@40 397 clock_time = clock () - start_clock ;
Chris@40 398 op_count ++ ;
Chris@40 399 } ;
Chris@40 400
Chris@40 401 performance = (1.0 * item_count) * BLOCK_COUNT * op_count ;
Chris@40 402 performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 403 printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ;
Chris@40 404
Chris@40 405 unlink (filename) ;
Chris@40 406
Chris@40 407 } /* calc_int_performance */
Chris@40 408 static void
Chris@40 409 calc_float_performance (int format, double read_rate, double write_rate)
Chris@40 410 { SNDFILE *file ;
Chris@40 411 SF_INFO sfinfo ;
Chris@40 412 clock_t start_clock, clock_time ;
Chris@40 413 double performance ;
Chris@40 414 int k, item_count, retval, op_count ;
Chris@40 415 const char* subtype ;
Chris@40 416 float *float_data ;
Chris@40 417 const char *filename ;
Chris@40 418
Chris@40 419 filename = "benchmark.dat" ;
Chris@40 420 subtype = get_subtype_str (format & SF_FORMAT_SUBMASK) ;
Chris@40 421
Chris@40 422 float_data = data ;
Chris@40 423 item_count = BUFFER_SIZE ;
Chris@40 424 for (k = 0 ; k < item_count ; k++)
Chris@40 425 float_data [k] = 1.0 * sin (2 * M_PI * k / 32000.0) ;
Chris@40 426
Chris@40 427 /* Collect write stats */
Chris@40 428 printf (" Write %-5s to %s : ", "float", subtype) ;
Chris@40 429 fflush (stdout) ;
Chris@40 430
Chris@40 431 sfinfo.channels = 1 ;
Chris@40 432 sfinfo.format = format ;
Chris@40 433 sfinfo.frames = 1 ;
Chris@40 434 sfinfo.samplerate = 32000 ;
Chris@40 435
Chris@40 436 clock_time = 0 ;
Chris@40 437 op_count = 0 ;
Chris@40 438 start_clock = clock () ;
Chris@40 439
Chris@40 440 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 441 { if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
Chris@40 442 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 443 perror ("") ;
Chris@40 444 exit (1) ;
Chris@40 445 } ;
Chris@40 446
Chris@40 447 /* Turn off the addition of a PEAK chunk. */
Chris@40 448 sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
Chris@40 449
Chris@40 450 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 451 { if ((retval = sf_write_float (file, float_data, item_count)) != item_count)
Chris@40 452 { printf ("Error : sf_write_short returned %d (should have been %d)\n", retval, item_count) ;
Chris@40 453 exit (1) ;
Chris@40 454 } ;
Chris@40 455 } ;
Chris@40 456
Chris@40 457 sf_close (file) ;
Chris@40 458
Chris@40 459 clock_time = clock () - start_clock ;
Chris@40 460 op_count ++ ;
Chris@40 461 } ;
Chris@40 462
Chris@40 463 performance = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
Chris@40 464 performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 465 printf ("%6.2f%% of raw write\n", 100.0 * performance / write_rate) ;
Chris@40 466
Chris@40 467 /* Collect read stats */
Chris@40 468 printf (" Read %-5s from %s : ", "float", subtype) ;
Chris@40 469 fflush (stdout) ;
Chris@40 470
Chris@40 471 clock_time = 0 ;
Chris@40 472 op_count = 0 ;
Chris@40 473 start_clock = clock () ;
Chris@40 474
Chris@40 475 while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
Chris@40 476 { if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
Chris@40 477 { printf ("Error : not able to open file : %s\n", filename) ;
Chris@40 478 perror ("") ;
Chris@40 479 exit (1) ;
Chris@40 480 } ;
Chris@40 481
Chris@40 482 for (k = 0 ; k < BLOCK_COUNT ; k++)
Chris@40 483 { if ((retval = sf_read_float (file, float_data, item_count)) != item_count)
Chris@40 484 { printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ;
Chris@40 485 exit (1) ;
Chris@40 486 } ;
Chris@40 487 } ;
Chris@40 488
Chris@40 489 sf_close (file) ;
Chris@40 490
Chris@40 491 clock_time = clock () - start_clock ;
Chris@40 492 op_count ++ ;
Chris@40 493 } ;
Chris@40 494
Chris@40 495 performance = (1.0 * item_count) * BLOCK_COUNT * op_count ;
Chris@40 496 performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
Chris@40 497 printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ;
Chris@40 498
Chris@40 499 unlink (filename) ;
Chris@40 500
Chris@40 501 } /* calc_float_performance */
Chris@40 502
Chris@40 503
Chris@40 504 /*==============================================================================
Chris@40 505 */
Chris@40 506
Chris@40 507 static int
Chris@40 508 cpu_is_big_endian (void)
Chris@40 509 { unsigned char *cptr ;
Chris@40 510 int endtest ;
Chris@40 511
Chris@40 512 endtest = 0x12345678 ;
Chris@40 513
Chris@40 514 cptr = (unsigned char*) (&endtest) ;
Chris@40 515
Chris@40 516 if (cptr [0] == 0x12 && cptr [1] == 0x34 && cptr [3] == 0x78)
Chris@40 517 return SF_TRUE ;
Chris@40 518
Chris@40 519 return SF_FALSE ;
Chris@40 520 } /* cpu_is_big_endian */
Chris@40 521
Chris@40 522 static const char*
Chris@40 523 get_subtype_str (int subtype)
Chris@40 524 { switch (subtype)
Chris@40 525 { case SF_FORMAT_PCM_16 :
Chris@40 526 return "PCM_16" ;
Chris@40 527
Chris@40 528 case SF_FORMAT_PCM_24 :
Chris@40 529 return "PCM_24" ;
Chris@40 530
Chris@40 531 case SF_FORMAT_PCM_32 :
Chris@40 532 return "PCM_32" ;
Chris@40 533
Chris@40 534 case SF_FORMAT_FLOAT :
Chris@40 535 return "FLOAT " ;
Chris@40 536
Chris@40 537 case SF_FORMAT_DOUBLE :
Chris@40 538 return "DOUBLE" ;
Chris@40 539
Chris@40 540 default : break ;
Chris@40 541 } ;
Chris@40 542
Chris@40 543 return "UNKNOWN" ;
Chris@40 544 } /* get_subtype_str */
Chris@40 545