<Kap, if you have a little binary you can send it to me, I have access to P4s, XPs and Tualatins.>
Just build this c source as p4_id.exe and run on the command line as say:
"p4_id.exe 100000 20000 > p4_gen.c"
This will generate a p4_gen.c file that has a loop and a switch. The first argument to p4_id.exe (100000) determines the number of iterations and the second (20000) determines the number of cases in the switch. You can try different number of iterations and cases to see were the P4 performance falls of the cliff.
Kap
#include "stdafx.h"
int main(int argc, char* argv[]) { int i, iterations = 100000, max_index = 1000; char name[20] = "p4_id.exe";
if (argc != 3) { printf("invokation error: p4_id.exe iterations max_index\n"); printf("iterations: number of times the switch statement is executed in the loop\n"); printf("max_index: number of cases the program will generate in the switch statement\n"); }
sscanf(argv[1], "%d", &iterations, &max_index); sscanf(argv[2], "%d", &max_index); printf("#include <time.h>\n"); printf("#include <stdlib.h>\n");
printf("int main() {\n"); printf("int i, sum;\n"); printf("srand( (unsigned)time( NULL ) );\n"); printf("for( i = 0; i < %d; i++ )\n",iterations); printf("switch ( rand() %% %d ){\n", max_index); for (i = 0; i < max_index; i++) printf("case %d: sum += %d; break;\n", i, i + 1); printf("default: sum = sum; }\n"); printf("return 0;\n}\n"); return 0; } |