Home | History | Annotate | Download | only in perf
      1 // This artificial program allocates and deallocates a lot of large objects
      2 // on the stack.  It is a stress test for Memcheck's set_address_range_perms
      3 // (sarp) function.  Pretty much all Valgrind versions up to 3.1.X do very
      4 // badly on it, ie. a slowdown of at least 100x.
      5 //
      6 // It is representative of tsim_arch, the simulator for the University of
      7 // Texas's TRIPS processor, whose performance under Valgrind is dominated by
      8 // the handling of one frequently-called function that allocates 8348 bytes
      9 // on the stack.
     10 
     11 #include <assert.h>
     12 #include <time.h>
     13 
     14 #define REPS   1000*1000*10
     15 
     16 __attribute__((noinline))
     17 int f(int i)
     18 {
     19    // This nonsense is just to ensure that the compiler does not optimise
     20    // away the stack allocation.
     21    char big_array[500];
     22    big_array[  0] = 12;
     23    big_array[ 23] = 34;
     24    big_array[256] = 56;
     25    big_array[434] = 78;
     26    assert( 480 == (&big_array[490] - &big_array[10]) );
     27    return big_array[i];
     28 }
     29 
     30 int main(void)
     31 {
     32    int i, sum = 0;
     33 
     34    struct timespec req __attribute__((unused));
     35    req.tv_sec  = 0;
     36    req.tv_nsec = 100*1000*1000;   // 0.1s
     37 
     38    // Pause for a bit so that the native run-time is not 0.00, which leads
     39    // to ridiculous slow-down figures.
     40    //nanosleep(&req, NULL);
     41 
     42    for (i = 0; i < REPS; i++) {
     43       sum += f(i & 0xff);
     44    }
     45    return ( sum == 0xdeadbeef ? 1 : 0 );
     46 }
     47 
     48