/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® quad-core |
Each table row shows performance measurements for this C++ g++ program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 500,000 | 3.10 | 2.44 | 4,620 | 588 | 6% 47% 48% 4% |
| 5,000,000 | 30.65 | 24.47 | 4,620 | 588 | 13% 36% 38% 11% |
| 50,000,000 | 302.58 | 229.41 | 4,620 | 588 | 35% 15% 15% 35% |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read thread-ring benchmark to see what this program should do.
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
/* * The Computer Language Benchmarks Game * http://benchmarksgame.alioth.debian.org/ * Contributed by Premysl Hruby * convert to C++ by The Anh Tran */ #include <pthread.h> #include <sched.h> #include <cstdio> #include <cstdlib> typedef unsigned int uint; const uint NUM_THREADS = 503; const uint STACK_SIZE = 16*1024; int token; pthread_mutex_t mutex [NUM_THREADS]; pthread_t threadid[NUM_THREADS]; char stacks [NUM_THREADS][STACK_SIZE]; static void* thread_func( void *num ) { size_t thisnode = reinterpret_cast<size_t>(num); int nextnode = ( thisnode + 1 ) % NUM_THREADS; pthread_mutex_t *mutex_this_node = mutex + thisnode; pthread_mutex_t *mutex_next_node = mutex + nextnode; while (true) { pthread_mutex_lock( mutex_this_node ); if ( token > 0 ) { token--; pthread_mutex_unlock( mutex_next_node ); } else { printf( "%d\n", static_cast<int>(thisnode +1) ); exit(0); } } return 0; } int main(int argc, char** args) { if (argc >= 2) token = atoi(args[1]); else token = 1000; // test case pthread_attr_t stack_attr; pthread_attr_init(&stack_attr); for (uint i = 0; i < NUM_THREADS; i++) { // init mutex objects pthread_mutex_init( &(mutex[i]), 0); pthread_mutex_lock( &(mutex[i]) ); // manual set stack space & stack size for each thread // to reduce memory usage pthread_attr_setstack( &stack_attr, &(stacks[i]), STACK_SIZE ); // create thread using specified stackspace pthread_create( &(threadid[i]), &stack_attr, &thread_func, reinterpret_cast<void*>(i) ); } // start game pthread_mutex_unlock( &(mutex[0]) ); // wait for result pthread_join( threadid[0], 0 ); return 1; }
Thu, 31 Jan 2013 23:38:03 GMT
MAKE:
/usr/bin/g++ -c -pipe -O3 -fomit-frame-pointer -march=native -pthread threadring.gpp-2.c++ -o threadring.gpp-2.c++.o && \
/usr/bin/g++ threadring.gpp-2.c++.o -o threadring.gpp-2.gpp_run -lpthread
rm threadring.gpp-2.c++
0.11s to complete and log all make actions
COMMAND LINE:
./threadring.gpp-2.gpp_run 50000000
PROGRAM OUTPUT:
292