njn | ec0c27a | 2005-12-10 23:11:28 +0000 | [diff] [blame] | 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 | |
sewardj | 57ea0c2 | 2005-12-13 17:13:39 +0000 | [diff] [blame] | 14 | #define REPS 1000*1000*10 |
njn | ec0c27a | 2005-12-10 23:11:28 +0000 | [diff] [blame] | 15 | |
njn | 79076e3 | 2005-12-14 05:33:17 +0000 | [diff] [blame] | 16 | __attribute__((noinline)) |
njn | ec0c27a | 2005-12-10 23:11:28 +0000 | [diff] [blame] | 17 | int f(int i) |
| 18 | { |
| 19 | // This nonsense is just to ensure that the compiler does not optimise |
| 20 | // away the stack allocation. |
sewardj | 57ea0c2 | 2005-12-13 17:13:39 +0000 | [diff] [blame] | 21 | char big_array[500]; |
njn | 79076e3 | 2005-12-14 05:33:17 +0000 | [diff] [blame] | 22 | big_array[ 0] = 12; |
sewardj | 57ea0c2 | 2005-12-13 17:13:39 +0000 | [diff] [blame] | 23 | big_array[ 23] = 34; |
| 24 | big_array[256] = 56; |
| 25 | big_array[434] = 78; |
| 26 | assert( 480 == (&big_array[490] - &big_array[10]) ); |
njn | ec0c27a | 2005-12-10 23:11:28 +0000 | [diff] [blame] | 27 | return big_array[i]; |
| 28 | } |
| 29 | |
| 30 | int main(void) |
| 31 | { |
| 32 | int i, sum = 0; |
| 33 | |
| 34 | struct timespec req; |
| 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. |
sewardj | 57ea0c2 | 2005-12-13 17:13:39 +0000 | [diff] [blame] | 40 | //nanosleep(&req, NULL); |
njn | ec0c27a | 2005-12-10 23:11:28 +0000 | [diff] [blame] | 41 | |
| 42 | for (i = 0; i < REPS; i++) { |
| 43 | sum += f(i & 0xff); |
| 44 | } |
njn | c870d18 | 2005-12-13 16:38:55 +0000 | [diff] [blame] | 45 | return ( sum == 0xdeadbeef ? 1 : 0 ); |
njn | ec0c27a | 2005-12-10 23:11:28 +0000 | [diff] [blame] | 46 | } |
| 47 | |