I/O operations refactoring.

This commit is contained in:
Igor Sysoev
2017-02-22 15:09:59 +03:00
parent 059a864289
commit 029942f4eb
49 changed files with 1145 additions and 1216 deletions

View File

@@ -1,72 +0,0 @@
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#include <nxt_main.h>
#include <math.h>
nxt_int_t
nxt_exp_approximation(nxt_thread_t *thr)
{
double n, e0, e1, diff;
nxt_nsec_t start, end;
nxt_thread_time_update(thr);
nxt_log_error(NXT_LOG_NOTICE, thr->log,
"exp approximation unit test started");
for (n = 0.0; n > -20.0; n -= 0.00001) {
e0 = nxt_event_conn_exponential_approximation(n);
e1 = exp(n);
diff = fabs(e0 - e1);
/* 0.028993 is max difference with libm exp(). */
if (diff > 0.028993) {
nxt_log_alert(thr->log,
"exp approximation unit test failed: %0.6f %0.6f",
n, diff);
return NXT_ERROR;
}
}
nxt_thread_time_update(thr);
start = nxt_thread_monotonic_time(thr);
e0 = 0;
for (n = 0.0; n > -20.0; n -= 0.00001) {
e0 += nxt_event_conn_exponential_approximation(n);
}
nxt_thread_time_update(thr);
end = nxt_thread_monotonic_time(thr);
/* e0 is passed but not output to eliminate optimization. */
nxt_log_error(NXT_LOG_NOTICE, thr->log, "exp approximation: %0.1fns",
(end - start) / 20000000.0, e0);
nxt_thread_time_update(thr);
start = nxt_thread_monotonic_time(thr);
e0 = 0;
for (n = 0.0; n > -20.0; n -= 0.000001) {
e0 += exp(n);
}
nxt_thread_time_update(thr);
end = nxt_thread_monotonic_time(thr);
/* e0 is passed but not output to eliminate optimization. */
nxt_log_error(NXT_LOG_NOTICE, thr->log, "libm exp(): %0.1fns",
(end - start) / 20000000.0, e0);
nxt_log_error(NXT_LOG_NOTICE, thr->log,
"exp approximation unit test passed");
return NXT_OK;
}

View File

@@ -77,10 +77,6 @@ main(int argc, char **argv)
return 1;
}
if (nxt_exp_approximation(thr) != NXT_OK) {
return 1;
}
if (nxt_rbtree_unit_test(thr, 100 * 1000) != NXT_OK) {
return 1;
}

View File

@@ -38,8 +38,6 @@ nxt_rdtsc(void)
nxt_int_t nxt_term_parse_unit_test(nxt_thread_t *thr);
nxt_int_t nxt_msec_diff_unit_test(nxt_thread_t *thr, nxt_msec_less_t);
nxt_int_t nxt_exp_approximation(nxt_thread_t *thr);
double nxt_event_conn_exponential_approximation(double n);
nxt_int_t nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n);
nxt_int_t nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n);