Skip to content

Instantly share code, notes, and snippets.

@coderarity
Created March 21, 2012 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderarity/2143360 to your computer and use it in GitHub Desktop.
Save coderarity/2143360 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
int main( int argc, char* argv[] ) {
int a;
struct timeval starttv, endtv;
time_t totalsec, totalusec, startsec, startusec;
double pps, totaltime;
if (argc < 2) {
a = 0;
}
else {
a = (long)strtol(argv[1], (char **)NULL, 10);
}
if (argc >= 4) {
startsec = (long)strtol(argv[2], (char **)NULL, 10);
startusec = (long)strtol(argv[3], (char **)NULL, 10);
}
else {
gettimeofday(&starttv, NULL);
startsec = starttv.tv_sec;
startusec = starttv.tv_usec;
}
a++;
gettimeofday(&endtv, NULL);
totalsec = endtv.tv_sec - startsec;
totalusec = endtv.tv_usec - startusec;
totaltime = (double)(totalsec)+((double)totalusec/1000000.0);
if (totaltime > 0) {
pps = (double)a/totaltime;
}
printf("%f\n", pps);
char* astr = (char*)malloc(sizeof(char)*256);
sprintf(astr, "%d", a);
char* tstr = (char*)malloc(sizeof(char)*256);
sprintf(tstr, "%ld", startsec);
char* tustr = (char*)malloc(sizeof(char)*256);
sprintf(tustr, "%ld", startusec);
//setsid();
int id = fork();
if (id == 0) {
execlp("unixfun", "unixfun", astr, tstr, tustr, NULL);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment