Testing with a toy program that determines the result of a tic-tac-toe board, I got this. What's making this quite big difference? I'd suspect that the calls to rand is faster with a statically linked libc, but still surprised with the result.
~$ gcc a.c -std=c11 -O3 ~$ time ./a.out 32614644 real 0m9.396s user 0m9.388s sys 0m0.004s ~$ gcc a.c -std=c11 -O3 -static ~$ time ./a.out 32614644 real 0m6.891s user 0m6.884s sys 0m0.000s #include <stdio.h> #include <stdlib.h> #define SIZE 3 #define SIZE_2 (SIZE * SIZE) static int determineResult(int board[static SIZE_2]) { for (int i = 0; i < SIZE_2; i += SIZE) { if (!board[i]) { continue; } for (int j = i + 1; j < i + SIZE; ++j) { if (board[i] != board[j]) { goto next; } } return board[i]; next:; } for (int i = 0; i < SIZE; ++i) { if (!board[i]) { continue; } for (int j = i + SIZE; j < i + SIZE_2; j += SIZE) { if (board[i] != board[j]) { goto next2; } } return board[i]; next2:; } for (int i = SIZE + 1; i < SIZE_2; i += SIZE + 1) { if (board[i] != *board) { goto next3; } } return *board; next3: for (int i = SIZE * 2 - 2; i <= SIZE_2 - SIZE; i += SIZE - 1) { if (board[i] != board[SIZE - 1]) { return 0; } } return board[SIZE - 1]; } #define N 50000000 int main(void) { srand(0); size_t n = 0; for (int i = 0; i < N; ++i) { int board[SIZE_2]; for (int i = 0; i < SIZE_2; ++i) { board[i] = rand() % 3; } n += determineResult(board); } printf("%zu\n", n); return EXIT_SUCCESS; }
mainwhich executes the relevant code a significant number of times.randor more exactlyrandom_ris consuming most of the time.