performance measurements

Each table row shows performance measurements for this C gcc program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,000Make Error  487   

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 version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)

 thread-ring C gcc program source code

/* The Computer Language Benchmarks Game

* contributed by Premysl Hruby

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <limits.h>

#define THREADS (503)

struct stack {

/* staticaly initialize mutex[0] mutex */
static pthread_mutex_t mutex[THREADS]; 
static int data[THREADS];
static struct stack stacks[THREADS];
/* stacks must be defined staticaly, or my i386 box run of virtual memory for this
 * process while creating thread +- #400 */

static void* thread(void *num)
   int l = (int)num;
   int r = (l+1) % THREADS;
   int token;

   while(1) {
      pthread_mutex_lock(mutex + l);
      token = data[l];
      if (token) {
         data[r] = token - 1;
         pthread_mutex_unlock(mutex + r);
      else {
         printf("%i\n", l+1);

int main(int argc, char **argv)
   int i;
   pthread_t cthread;
   pthread_attr_t stack_attr;

   if (argc != 2)
   data[0] = atoi(argv[1]);

   for (i = 0; i < THREADS; i++) {
      pthread_mutex_init(mutex + i, NULL);
      pthread_mutex_lock(mutex + i);

      pthread_attr_setstack(&stack_attr, &stacks[i], sizeof(struct stack)); 
      pthread_create(&cthread, &stack_attr, thread, (void*)i);

   pthread_mutex_unlock(mutex + 0);
   pthread_join(cthread, NULL);   

 make, command-line, and program output logs

Tue, 28 Apr 2015 20:55:51 GMT

/usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -march=native -pthread -std=c99 threadring.c -o threadring.gcc_run 
threadring.c:17:11: error: ‘PTHREAD_STACK_MIN’ undeclared here (not in a function)
    char x[PTHREAD_STACK_MIN];
threadring.c: In function ‘main’:
threadring.c:66:7: warning: implicit declaration of function ‘pthread_attr_setstack’ [-Wimplicit-function-declaration]
       pthread_attr_setstack(&stack_attr, &stacks[i], sizeof(struct stack)); 
/home/dunham/benchmarksgame/nanobench/makefiles/u32q.programs.Makefile:56: recipe for target 'threadring.gcc_run' failed
make: [threadring.gcc_run] Error 1 (ignored)
rm threadring.c
0.07s to complete and log all make actions

./threadring.gcc_run 500000


Revised BSD license

  Home   Conclusions   License   Play