bench.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2015, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /* Ordinarily defined in tor_main.c; this bit is just here to provide one
  6. * since we're not linking to tor_main.c */
  7. const char tor_git_revision[] = "";
  8. /**
  9. * \file bench.c
  10. * \brief Benchmarks for lower level Tor modules.
  11. **/
  12. #include "orconfig.h"
  13. #include "or.h"
  14. #include "onion_tap.h"
  15. #include "relay.h"
  16. #include <openssl/opensslv.h>
  17. #include <openssl/evp.h>
  18. #include <openssl/ec.h>
  19. #include <openssl/ecdh.h>
  20. #include <openssl/obj_mac.h>
  21. #include "config.h"
  22. #include "crypto_curve25519.h"
  23. #include "onion_ntor.h"
  24. #include "crypto_ed25519.h"
  25. #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
  26. static uint64_t nanostart;
  27. static inline uint64_t
  28. timespec_to_nsec(const struct timespec *ts)
  29. {
  30. return ((uint64_t)ts->tv_sec)*1000000000 + ts->tv_nsec;
  31. }
  32. static void
  33. reset_perftime(void)
  34. {
  35. struct timespec ts;
  36. int r;
  37. r = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
  38. tor_assert(r == 0);
  39. nanostart = timespec_to_nsec(&ts);
  40. }
  41. static uint64_t
  42. perftime(void)
  43. {
  44. struct timespec ts;
  45. int r;
  46. r = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
  47. tor_assert(r == 0);
  48. return timespec_to_nsec(&ts) - nanostart;
  49. }
  50. #else
  51. static struct timeval tv_start = { 0, 0 };
  52. static void
  53. reset_perftime(void)
  54. {
  55. tor_gettimeofday(&tv_start);
  56. }
  57. static uint64_t
  58. perftime(void)
  59. {
  60. struct timeval now, out;
  61. tor_gettimeofday(&now);
  62. timersub(&now, &tv_start, &out);
  63. return ((uint64_t)out.tv_sec)*1000000000 + out.tv_usec*1000;
  64. }
  65. #endif
  66. #define NANOCOUNT(start,end,iters) \
  67. ( ((double)((end)-(start))) / (iters) )
  68. #define MICROCOUNT(start,end,iters) \
  69. ( NANOCOUNT((start), (end), (iters)) / 1000.0 )
  70. /** Run AES performance benchmarks. */
  71. static void
  72. bench_aes(void)
  73. {
  74. int len, i;
  75. char *b1, *b2;
  76. crypto_cipher_t *c;
  77. uint64_t start, end;
  78. const int bytes_per_iter = (1<<24);
  79. reset_perftime();
  80. c = crypto_cipher_new(NULL);
  81. for (len = 1; len <= 8192; len *= 2) {
  82. int iters = bytes_per_iter / len;
  83. b1 = tor_malloc_zero(len);
  84. b2 = tor_malloc_zero(len);
  85. start = perftime();
  86. for (i = 0; i < iters; ++i) {
  87. crypto_cipher_encrypt(c, b1, b2, len);
  88. }
  89. end = perftime();
  90. tor_free(b1);
  91. tor_free(b2);
  92. printf("%d bytes: %.2f nsec per byte\n", len,
  93. NANOCOUNT(start, end, iters*len));
  94. }
  95. crypto_cipher_free(c);
  96. }
  97. static void
  98. bench_onion_TAP(void)
  99. {
  100. const int iters = 1<<9;
  101. int i;
  102. crypto_pk_t *key, *key2;
  103. uint64_t start, end;
  104. char os[TAP_ONIONSKIN_CHALLENGE_LEN];
  105. char or[TAP_ONIONSKIN_REPLY_LEN];
  106. crypto_dh_t *dh_out;
  107. key = crypto_pk_new();
  108. key2 = crypto_pk_new();
  109. if (crypto_pk_generate_key_with_bits(key, 1024) < 0)
  110. goto done;
  111. if (crypto_pk_generate_key_with_bits(key2, 1024) < 0)
  112. goto done;
  113. reset_perftime();
  114. start = perftime();
  115. for (i = 0; i < iters; ++i) {
  116. onion_skin_TAP_create(key, &dh_out, os);
  117. crypto_dh_free(dh_out);
  118. }
  119. end = perftime();
  120. printf("Client-side, part 1: %f usec.\n", NANOCOUNT(start, end, iters)/1e3);
  121. onion_skin_TAP_create(key, &dh_out, os);
  122. start = perftime();
  123. for (i = 0; i < iters; ++i) {
  124. char key_out[CPATH_KEY_MATERIAL_LEN];
  125. onion_skin_TAP_server_handshake(os, key, NULL, or,
  126. key_out, sizeof(key_out));
  127. }
  128. end = perftime();
  129. printf("Server-side, key guessed right: %f usec\n",
  130. NANOCOUNT(start, end, iters)/1e3);
  131. start = perftime();
  132. for (i = 0; i < iters; ++i) {
  133. char key_out[CPATH_KEY_MATERIAL_LEN];
  134. onion_skin_TAP_server_handshake(os, key2, key, or,
  135. key_out, sizeof(key_out));
  136. }
  137. end = perftime();
  138. printf("Server-side, key guessed wrong: %f usec.\n",
  139. NANOCOUNT(start, end, iters)/1e3);
  140. start = perftime();
  141. for (i = 0; i < iters; ++i) {
  142. crypto_dh_t *dh;
  143. char key_out[CPATH_KEY_MATERIAL_LEN];
  144. int s;
  145. dh = crypto_dh_dup(dh_out);
  146. s = onion_skin_TAP_client_handshake(dh, or, key_out, sizeof(key_out),
  147. NULL);
  148. crypto_dh_free(dh);
  149. tor_assert(s == 0);
  150. }
  151. end = perftime();
  152. printf("Client-side, part 2: %f usec.\n",
  153. NANOCOUNT(start, end, iters)/1e3);
  154. done:
  155. crypto_pk_free(key);
  156. crypto_pk_free(key2);
  157. }
  158. static void
  159. bench_onion_ntor(void)
  160. {
  161. const int iters = 1<<10;
  162. int i;
  163. curve25519_keypair_t keypair1, keypair2;
  164. uint64_t start, end;
  165. uint8_t os[NTOR_ONIONSKIN_LEN];
  166. uint8_t or[NTOR_REPLY_LEN];
  167. ntor_handshake_state_t *state = NULL;
  168. uint8_t nodeid[DIGEST_LEN];
  169. di_digest256_map_t *keymap = NULL;
  170. curve25519_secret_key_generate(&keypair1.seckey, 0);
  171. curve25519_public_key_generate(&keypair1.pubkey, &keypair1.seckey);
  172. curve25519_secret_key_generate(&keypair2.seckey, 0);
  173. curve25519_public_key_generate(&keypair2.pubkey, &keypair2.seckey);
  174. dimap_add_entry(&keymap, keypair1.pubkey.public_key, &keypair1);
  175. dimap_add_entry(&keymap, keypair2.pubkey.public_key, &keypair2);
  176. reset_perftime();
  177. start = perftime();
  178. for (i = 0; i < iters; ++i) {
  179. onion_skin_ntor_create(nodeid, &keypair1.pubkey, &state, os);
  180. ntor_handshake_state_free(state);
  181. state = NULL;
  182. }
  183. end = perftime();
  184. printf("Client-side, part 1: %f usec.\n", NANOCOUNT(start, end, iters)/1e3);
  185. state = NULL;
  186. onion_skin_ntor_create(nodeid, &keypair1.pubkey, &state, os);
  187. start = perftime();
  188. for (i = 0; i < iters; ++i) {
  189. uint8_t key_out[CPATH_KEY_MATERIAL_LEN];
  190. onion_skin_ntor_server_handshake(os, keymap, NULL, nodeid, or,
  191. key_out, sizeof(key_out));
  192. }
  193. end = perftime();
  194. printf("Server-side: %f usec\n",
  195. NANOCOUNT(start, end, iters)/1e3);
  196. start = perftime();
  197. for (i = 0; i < iters; ++i) {
  198. uint8_t key_out[CPATH_KEY_MATERIAL_LEN];
  199. int s;
  200. s = onion_skin_ntor_client_handshake(state, or, key_out, sizeof(key_out),
  201. NULL);
  202. tor_assert(s == 0);
  203. }
  204. end = perftime();
  205. printf("Client-side, part 2: %f usec.\n",
  206. NANOCOUNT(start, end, iters)/1e3);
  207. ntor_handshake_state_free(state);
  208. dimap_free(keymap, NULL);
  209. }
  210. static void
  211. bench_ed25519(void)
  212. {
  213. uint64_t start, end;
  214. const int iters = 1<<12;
  215. int i;
  216. const uint8_t msg[] = "but leaving, could not tell what they had heard";
  217. ed25519_signature_t sig;
  218. ed25519_keypair_t kp;
  219. curve25519_keypair_t curve_kp;
  220. ed25519_public_key_t pubkey_tmp;
  221. ed25519_secret_key_generate(&kp.seckey, 0);
  222. start = perftime();
  223. for (i = 0; i < iters; ++i) {
  224. ed25519_public_key_generate(&kp.pubkey, &kp.seckey);
  225. }
  226. end = perftime();
  227. printf("Generate public key: %.2f usec\n",
  228. MICROCOUNT(start, end, iters));
  229. start = perftime();
  230. for (i = 0; i < iters; ++i) {
  231. ed25519_sign(&sig, msg, sizeof(msg), &kp);
  232. }
  233. end = perftime();
  234. printf("Sign a short message: %.2f usec\n",
  235. MICROCOUNT(start, end, iters));
  236. start = perftime();
  237. for (i = 0; i < iters; ++i) {
  238. ed25519_checksig(&sig, msg, sizeof(msg), &kp.pubkey);
  239. }
  240. end = perftime();
  241. printf("Verify signature: %.2f usec\n",
  242. MICROCOUNT(start, end, iters));
  243. curve25519_keypair_generate(&curve_kp, 0);
  244. start = perftime();
  245. for (i = 0; i < iters; ++i) {
  246. ed25519_public_key_from_curve25519_public_key(&pubkey_tmp,
  247. &curve_kp.pubkey, 1);
  248. }
  249. end = perftime();
  250. printf("Convert public point from curve25519: %.2f usec\n",
  251. MICROCOUNT(start, end, iters));
  252. curve25519_keypair_generate(&curve_kp, 0);
  253. start = perftime();
  254. for (i = 0; i < iters; ++i) {
  255. ed25519_public_blind(&pubkey_tmp, &kp.pubkey, msg);
  256. }
  257. end = perftime();
  258. printf("Blind a public key: %.2f usec\n",
  259. MICROCOUNT(start, end, iters));
  260. }
  261. static void
  262. bench_cell_aes(void)
  263. {
  264. uint64_t start, end;
  265. const int len = 509;
  266. const int iters = (1<<16);
  267. const int max_misalign = 15;
  268. char *b = tor_malloc(len+max_misalign);
  269. crypto_cipher_t *c;
  270. int i, misalign;
  271. c = crypto_cipher_new(NULL);
  272. reset_perftime();
  273. for (misalign = 0; misalign <= max_misalign; ++misalign) {
  274. start = perftime();
  275. for (i = 0; i < iters; ++i) {
  276. crypto_cipher_crypt_inplace(c, b+misalign, len);
  277. }
  278. end = perftime();
  279. printf("%d bytes, misaligned by %d: %.2f nsec per byte\n", len, misalign,
  280. NANOCOUNT(start, end, iters*len));
  281. }
  282. crypto_cipher_free(c);
  283. tor_free(b);
  284. }
  285. /** Run digestmap_t performance benchmarks. */
  286. static void
  287. bench_dmap(void)
  288. {
  289. smartlist_t *sl = smartlist_new();
  290. smartlist_t *sl2 = smartlist_new();
  291. uint64_t start, end, pt2, pt3, pt4;
  292. int iters = 8192;
  293. const int elts = 4000;
  294. const int fpostests = 100000;
  295. char d[20];
  296. int i,n=0, fp = 0;
  297. digestmap_t *dm = digestmap_new();
  298. digestset_t *ds = digestset_new(elts);
  299. for (i = 0; i < elts; ++i) {
  300. crypto_rand(d, 20);
  301. smartlist_add(sl, tor_memdup(d, 20));
  302. }
  303. for (i = 0; i < elts; ++i) {
  304. crypto_rand(d, 20);
  305. smartlist_add(sl2, tor_memdup(d, 20));
  306. }
  307. printf("nbits=%d\n", ds->mask+1);
  308. reset_perftime();
  309. start = perftime();
  310. for (i = 0; i < iters; ++i) {
  311. SMARTLIST_FOREACH(sl, const char *, cp, digestmap_set(dm, cp, (void*)1));
  312. }
  313. pt2 = perftime();
  314. printf("digestmap_set: %.2f ns per element\n",
  315. NANOCOUNT(start, pt2, iters*elts));
  316. for (i = 0; i < iters; ++i) {
  317. SMARTLIST_FOREACH(sl, const char *, cp, digestmap_get(dm, cp));
  318. SMARTLIST_FOREACH(sl2, const char *, cp, digestmap_get(dm, cp));
  319. }
  320. pt3 = perftime();
  321. printf("digestmap_get: %.2f ns per element\n",
  322. NANOCOUNT(pt2, pt3, iters*elts*2));
  323. for (i = 0; i < iters; ++i) {
  324. SMARTLIST_FOREACH(sl, const char *, cp, digestset_add(ds, cp));
  325. }
  326. pt4 = perftime();
  327. printf("digestset_add: %.2f ns per element\n",
  328. NANOCOUNT(pt3, pt4, iters*elts));
  329. for (i = 0; i < iters; ++i) {
  330. SMARTLIST_FOREACH(sl, const char *, cp, n += digestset_contains(ds, cp));
  331. SMARTLIST_FOREACH(sl2, const char *, cp, n += digestset_contains(ds, cp));
  332. }
  333. end = perftime();
  334. printf("digestset_contains: %.2f ns per element.\n",
  335. NANOCOUNT(pt4, end, iters*elts*2));
  336. /* We need to use this, or else the whole loop gets optimized out. */
  337. printf("Hits == %d\n", n);
  338. for (i = 0; i < fpostests; ++i) {
  339. crypto_rand(d, 20);
  340. if (digestset_contains(ds, d)) ++fp;
  341. }
  342. printf("False positive rate on digestset: %.2f%%\n",
  343. (fp/(double)fpostests)*100);
  344. digestmap_free(dm, NULL);
  345. digestset_free(ds);
  346. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  347. SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp));
  348. smartlist_free(sl);
  349. smartlist_free(sl2);
  350. }
  351. static void
  352. bench_siphash(void)
  353. {
  354. char buf[128];
  355. int lens[] = { 7, 8, 15, 16, 20, 32, 111, 128, -1 };
  356. int i, j;
  357. uint64_t start, end;
  358. const int N = 300000;
  359. crypto_rand(buf, sizeof(buf));
  360. for (i = 0; lens[i] > 0; ++i) {
  361. reset_perftime();
  362. start = perftime();
  363. for (j = 0; j < N; ++j) {
  364. siphash24g(buf, lens[i]);
  365. }
  366. end = perftime();
  367. printf("siphash24g(%d): %.2f ns per call\n",
  368. lens[i], NANOCOUNT(start,end,N));
  369. }
  370. }
  371. static void
  372. bench_cell_ops(void)
  373. {
  374. const int iters = 1<<16;
  375. int i;
  376. /* benchmarks for cell ops at relay. */
  377. or_circuit_t *or_circ = tor_malloc_zero(sizeof(or_circuit_t));
  378. cell_t *cell = tor_malloc(sizeof(cell_t));
  379. int outbound;
  380. uint64_t start, end;
  381. crypto_rand((char*)cell->payload, sizeof(cell->payload));
  382. /* Mock-up or_circuit_t */
  383. or_circ->base_.magic = OR_CIRCUIT_MAGIC;
  384. or_circ->base_.purpose = CIRCUIT_PURPOSE_OR;
  385. /* Initialize crypto */
  386. or_circ->p_crypto = crypto_cipher_new(NULL);
  387. or_circ->n_crypto = crypto_cipher_new(NULL);
  388. or_circ->p_digest = crypto_digest_new();
  389. or_circ->n_digest = crypto_digest_new();
  390. reset_perftime();
  391. for (outbound = 0; outbound <= 1; ++outbound) {
  392. cell_direction_t d = outbound ? CELL_DIRECTION_OUT : CELL_DIRECTION_IN;
  393. start = perftime();
  394. for (i = 0; i < iters; ++i) {
  395. char recognized = 0;
  396. crypt_path_t *layer_hint = NULL;
  397. relay_crypt(TO_CIRCUIT(or_circ), cell, d, &layer_hint, &recognized);
  398. }
  399. end = perftime();
  400. printf("%sbound cells: %.2f ns per cell. (%.2f ns per byte of payload)\n",
  401. outbound?"Out":" In",
  402. NANOCOUNT(start,end,iters),
  403. NANOCOUNT(start,end,iters*CELL_PAYLOAD_SIZE));
  404. }
  405. crypto_digest_free(or_circ->p_digest);
  406. crypto_digest_free(or_circ->n_digest);
  407. crypto_cipher_free(or_circ->p_crypto);
  408. crypto_cipher_free(or_circ->n_crypto);
  409. tor_free(or_circ);
  410. tor_free(cell);
  411. }
  412. static void
  413. bench_dh(void)
  414. {
  415. const int iters = 1<<10;
  416. int i;
  417. uint64_t start, end;
  418. reset_perftime();
  419. start = perftime();
  420. for (i = 0; i < iters; ++i) {
  421. char dh_pubkey_a[DH_BYTES], dh_pubkey_b[DH_BYTES];
  422. char secret_a[DH_BYTES], secret_b[DH_BYTES];
  423. ssize_t slen_a, slen_b;
  424. crypto_dh_t *dh_a = crypto_dh_new(DH_TYPE_TLS);
  425. crypto_dh_t *dh_b = crypto_dh_new(DH_TYPE_TLS);
  426. crypto_dh_generate_public(dh_a);
  427. crypto_dh_generate_public(dh_b);
  428. crypto_dh_get_public(dh_a, dh_pubkey_a, sizeof(dh_pubkey_a));
  429. crypto_dh_get_public(dh_b, dh_pubkey_b, sizeof(dh_pubkey_b));
  430. slen_a = crypto_dh_compute_secret(LOG_NOTICE,
  431. dh_a, dh_pubkey_b, sizeof(dh_pubkey_b),
  432. secret_a, sizeof(secret_a));
  433. slen_b = crypto_dh_compute_secret(LOG_NOTICE,
  434. dh_b, dh_pubkey_a, sizeof(dh_pubkey_a),
  435. secret_b, sizeof(secret_b));
  436. tor_assert(slen_a == slen_b);
  437. tor_assert(!memcmp(secret_a, secret_b, slen_a));
  438. crypto_dh_free(dh_a);
  439. crypto_dh_free(dh_b);
  440. }
  441. end = perftime();
  442. printf("Complete DH handshakes (1024 bit, public and private ops):\n"
  443. " %f millisec each.\n", NANOCOUNT(start, end, iters)/1e6);
  444. }
  445. static void
  446. bench_ecdh_impl(int nid, const char *name)
  447. {
  448. const int iters = 1<<10;
  449. int i;
  450. uint64_t start, end;
  451. reset_perftime();
  452. start = perftime();
  453. for (i = 0; i < iters; ++i) {
  454. char secret_a[DH_BYTES], secret_b[DH_BYTES];
  455. ssize_t slen_a, slen_b;
  456. EC_KEY *dh_a = EC_KEY_new_by_curve_name(nid);
  457. EC_KEY *dh_b = EC_KEY_new_by_curve_name(nid);
  458. if (!dh_a || !dh_b) {
  459. puts("Skipping. (No implementation?)");
  460. return;
  461. }
  462. EC_KEY_generate_key(dh_a);
  463. EC_KEY_generate_key(dh_b);
  464. slen_a = ECDH_compute_key(secret_a, DH_BYTES,
  465. EC_KEY_get0_public_key(dh_b), dh_a,
  466. NULL);
  467. slen_b = ECDH_compute_key(secret_b, DH_BYTES,
  468. EC_KEY_get0_public_key(dh_a), dh_b,
  469. NULL);
  470. tor_assert(slen_a == slen_b);
  471. tor_assert(!memcmp(secret_a, secret_b, slen_a));
  472. EC_KEY_free(dh_a);
  473. EC_KEY_free(dh_b);
  474. }
  475. end = perftime();
  476. printf("Complete ECDH %s handshakes (2 public and 2 private ops):\n"
  477. " %f millisec each.\n", name, NANOCOUNT(start, end, iters)/1e6);
  478. }
  479. static void
  480. bench_ecdh_p256(void)
  481. {
  482. bench_ecdh_impl(NID_X9_62_prime256v1, "P-256");
  483. }
  484. static void
  485. bench_ecdh_p224(void)
  486. {
  487. bench_ecdh_impl(NID_secp224r1, "P-224");
  488. }
  489. typedef void (*bench_fn)(void);
  490. typedef struct benchmark_t {
  491. const char *name;
  492. bench_fn fn;
  493. int enabled;
  494. } benchmark_t;
  495. #define ENT(s) { #s , bench_##s, 0 }
  496. static struct benchmark_t benchmarks[] = {
  497. ENT(dmap),
  498. ENT(siphash),
  499. ENT(aes),
  500. ENT(onion_TAP),
  501. ENT(onion_ntor),
  502. ENT(ed25519),
  503. ENT(cell_aes),
  504. ENT(cell_ops),
  505. ENT(dh),
  506. ENT(ecdh_p256),
  507. ENT(ecdh_p224),
  508. {NULL,NULL,0}
  509. };
  510. static benchmark_t *
  511. find_benchmark(const char *name)
  512. {
  513. benchmark_t *b;
  514. for (b = benchmarks; b->name; ++b) {
  515. if (!strcmp(name, b->name)) {
  516. return b;
  517. }
  518. }
  519. return NULL;
  520. }
  521. /** Main entry point for benchmark code: parse the command line, and run
  522. * some benchmarks. */
  523. int
  524. main(int argc, const char **argv)
  525. {
  526. int i;
  527. int list=0, n_enabled=0;
  528. benchmark_t *b;
  529. char *errmsg;
  530. or_options_t *options;
  531. tor_threads_init();
  532. for (i = 1; i < argc; ++i) {
  533. if (!strcmp(argv[i], "--list")) {
  534. list = 1;
  535. } else {
  536. benchmark_t *b = find_benchmark(argv[i]);
  537. ++n_enabled;
  538. if (b) {
  539. b->enabled = 1;
  540. } else {
  541. printf("No such benchmark as %s\n", argv[i]);
  542. }
  543. }
  544. }
  545. reset_perftime();
  546. crypto_seed_rng();
  547. crypto_init_siphash_key();
  548. options = options_new();
  549. init_logging(1);
  550. options->command = CMD_RUN_UNITTESTS;
  551. options->DataDirectory = tor_strdup("");
  552. options_init(options);
  553. if (set_options(options, &errmsg) < 0) {
  554. printf("Failed to set initial options: %s\n", errmsg);
  555. tor_free(errmsg);
  556. return 1;
  557. }
  558. for (b = benchmarks; b->name; ++b) {
  559. if (b->enabled || n_enabled == 0) {
  560. printf("===== %s =====\n", b->name);
  561. if (!list)
  562. b->fn();
  563. }
  564. }
  565. return 0;
  566. }