commit
2c405f40a9
3 changed files with 20 additions and 2 deletions
|
|
@ -10,7 +10,13 @@
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void h_benchmark_clock_gettime(struct timespec *ts) {
|
void h_benchmark_clock_gettime(struct timespec *ts) {
|
||||||
|
if (ts == NULL)
|
||||||
|
return;
|
||||||
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
|
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
|
||||||
/*
|
/*
|
||||||
* This returns real time, not CPU time. See http://stackoverflow.com/a/6725161
|
* This returns real time, not CPU time. See http://stackoverflow.com/a/6725161
|
||||||
|
|
@ -23,6 +29,18 @@ void h_benchmark_clock_gettime(struct timespec *ts) {
|
||||||
mach_port_deallocate(mach_task_self(), cclock);
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
ts->tv_sec = mts.tv_sec;
|
ts->tv_sec = mts.tv_sec;
|
||||||
ts->tv_nsec = mts.tv_nsec;
|
ts->tv_nsec = mts.tv_nsec;
|
||||||
|
#elif defined(__NetBSD__)
|
||||||
|
// NetBSD doesn't have CLOCK_THREAD_CPUTIME_ID. We'll use getrusage instead
|
||||||
|
struct rusage rusage;
|
||||||
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
|
ts->tv_nsec = (rusage.ru_utime.tv_usec + rusage.ru_stime.tv_usec) * 1000;
|
||||||
|
// not going to overflow; can be at most 2e9-2
|
||||||
|
ts->tv_sec = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_sec;
|
||||||
|
if (ts->tv_nsec >= 1000000000) {
|
||||||
|
ts->tv_nsec -= 1000000000; // subtract a second
|
||||||
|
ts->tv_sec += 1; // add it back.
|
||||||
|
}
|
||||||
|
assert (ts->tv_nsec <= 1000000000);
|
||||||
#else
|
#else
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts);
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -648,7 +648,7 @@ void h_pprint_char(FILE *f, char c)
|
||||||
case '\n': fputs("\\n", f); break;
|
case '\n': fputs("\\n", f); break;
|
||||||
case '\r': fputs("\\r", f); break;
|
case '\r': fputs("\\r", f); break;
|
||||||
default:
|
default:
|
||||||
if(isprint(c)) {
|
if(isprint((int)c)) {
|
||||||
fputc(c, f);
|
fputc(c, f);
|
||||||
} else {
|
} else {
|
||||||
fprintf(f, "\\x%.2X", c);
|
fprintf(f, "\\x%.2X", c);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ static HParseResult* parse_whitespace(void* env, HParseState *state) {
|
||||||
c = h_read_bits(&state->input_stream, 8, false);
|
c = h_read_bits(&state->input_stream, 8, false);
|
||||||
if (state->input_stream.overrun)
|
if (state->input_stream.overrun)
|
||||||
break;
|
break;
|
||||||
} while (isspace(c));
|
} while (isspace((int)c));
|
||||||
state->input_stream = bak;
|
state->input_stream = bak;
|
||||||
return h_do_parse((HParser*)env, state);
|
return h_do_parse((HParser*)env, state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue