1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/bench/benchsyscall.c

46 lines
1.4 KiB
C
Raw Normal View History

/*
* Copyright (c) 2011 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* benchsyscall.c
* Benchmarks the speed of system calls.
*/
2015-06-10 17:24:25 -04:00
#include <err.h>
#include <stdio.h>
#include <unistd.h>
2013-05-14 04:07:56 -04:00
#include <time.h>
static int uptime(uintmax_t* usecs)
{
struct timespec uptime;
if ( clock_gettime(CLOCK_BOOT, &uptime) < 0 )
return -1;
*usecs = uptime.tv_sec * 1000000ULL + uptime.tv_nsec / 1000ULL;
return 0;
}
2016-02-28 10:42:57 -05:00
int main(void)
{
uintmax_t start;
2015-06-10 17:24:25 -04:00
if ( uptime(&start) )
err(1, "uptime");
uintmax_t end = start + 1ULL * 1000ULL * 1000ULL; // 1 second
size_t count = 0;
uintmax_t now;
while ( !uptime(&now) && now < end ) { count++; }
printf("Made %zu system calls in 1 second\n", count);
return 0;
}