add a new -bulk command line option which can be used in pipe mode
[rofl0r-jobflow.git] / tests / cpuwaster.c
blob54237abb41970919570f5943e9b6adb38bba6693
1 #include "../lib/include/timelib.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
6 int syntax() {
7 puts("prog seconds_of_cpu_time_to_burn");
8 return 1;
11 long parse_human_number(char* num) {
12 long ret = 0;
13 char buf[64];
14 if(!num) return 0;
15 size_t l = strlen(num);
17 if(l && l < sizeof(buf)) {
18 if(num[l -1] == 'G')
19 ret = 1024 * 1024 * 1024;
20 else if(num[l -1] == 'M')
21 ret = 1024 * 1024;
22 else if(num[l -1] == 'K')
23 ret = 1024;
24 if(ret) {
25 memcpy(buf, num, l);
26 buf[l] = 0;
27 return atol(buf) * ret;
29 return atol(num);
31 return ret;
34 int main(int argc, char** argv) {
35 void* buf;
36 long waste_secs;
37 struct timeval start;
38 if (argc != 2) return syntax();
39 waste_secs = parse_human_number(argv[1]);
40 gettimestamp(&start);
42 while(mspassed(&start) < waste_secs * 1000) {}
44 printf("successfully wasted %lu seconds of your cpu time\n", waste_secs);
45 return 0;