Skip to content

Instantly share code, notes, and snippets.

@aji
Created May 24, 2013 03:05
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 aji/5641036 to your computer and use it in GitHub Desktop.
Save aji/5641036 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char buf[512];
char *args[3] = { argv[0], NULL, NULL };
int x = (argc > 1 ? atoi(argv[1]) : 0) + 1;
if (x == 10000)
return puts("done") && 0;
snprintf(buf, 512, "%d", x);
args[1] = buf;
execv(args[0], args);
}
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char buf[512] = "";
int x;
top:
x = (buf[0] ? atoi(buf) : 0) + 1;
if (x == 10000)
return puts("done") && 0;
snprintf(buf, 512, "%d", x);
goto top;
}
theta ~/work/sandbox/sexec$ time ./sexec
done
real 0m4.834s
user 0m1.207s
sys 0m3.540s
theta ~/work/sandbox/sexec$ time ./sprint
done
real 0m0.005s
user 0m0.003s
sys 0m0.000s
theta ~/work/sandbox/sexec$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment