-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "cpu_time.h" | ||
|
||
#include <time.h> | ||
|
||
struct timespec t0; | ||
|
||
static struct timespec diff(const struct timespec *start, const struct timespec *end) | ||
{ | ||
struct timespec temp; | ||
if ((end->tv_nsec - start->tv_nsec)<0) { | ||
temp.tv_sec = end->tv_sec - start->tv_sec - 1; | ||
temp.tv_nsec = 1000000000 + end->tv_nsec - start->tv_nsec; | ||
} else { | ||
temp.tv_sec = end->tv_sec - start->tv_sec; | ||
temp.tv_nsec = end->tv_nsec - start->tv_nsec; | ||
} | ||
return temp; | ||
} | ||
|
||
void cpu_time_start() { | ||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0); | ||
} | ||
|
||
unsigned long int cpu_time_get_delta_ns() { | ||
struct timespec t1; | ||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1); | ||
struct timespec delta = diff(&t0, &t1); | ||
return (delta.tv_sec * 1000000000) + delta.tv_nsec; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// extremely simple CPU time measurement module, for benchmarking | ||
// sets a single reference point, and computes time deltas since that point | ||
|
||
#pragma once | ||
|
||
extern void cpu_time_start(); | ||
|
||
extern unsigned long int cpu_time_get_delta_ns(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters