Skip to content

Commit 9cc9aa7

Browse files
committed
added timer API for easy time tracking
1 parent 20c86e7 commit 9cc9aa7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

timer.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <time.h>
2+
#include "display.h"
3+
4+
static clock_t start = 0, end = 0;
5+
static const char* runningJob[] = {"Nothing"};
6+
7+
void timer_end(){
8+
if(start != 0){
9+
end = clock();
10+
double sec = (double)(end-start)/CLOCKS_PER_SEC;
11+
info("%s finished in %f seconds\n", runningJob[0], sec);
12+
start = end = 0;
13+
runningJob[0] = "Nothing";
14+
}
15+
}
16+
17+
void timer_start(const char* job){
18+
if(start != 0)
19+
timer_end();
20+
runningJob[0] = job;
21+
info("Started %s\n", job);
22+
start = clock();
23+
}

timer.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
void timer_start(const char* job);
4+
void timer_end();

0 commit comments

Comments
 (0)