| 373 | } |
| 374 | |
| 375 | void testSerializationSpeed() { |
| 376 | double tstart; |
| 377 | double build = 0, serialize = 0, deserialize = 0, copy = 0, deallocate = 0; |
| 378 | double bytes = 0; |
| 379 | double testBegin = timer(); |
| 380 | for (int a = 0; a < 10000; a++) { |
| 381 | { |
| 382 | tstart = timer(); |
| 383 | |
| 384 | Arena batchArena; |
| 385 | VectorRef<CommitTransactionRef> batch; |
| 386 | batch.resize(batchArena, 1000); |
| 387 | for (int t = 0; t < batch.size(); t++) { |
| 388 | CommitTransactionRef& tr = batch[t]; |
| 389 | tr.read_snapshot = 0; |
| 390 | for (int i = 0; i < 2; i++) |
| 391 | tr.mutations.push_back_deep( |
| 392 | batchArena, |
| 393 | MutationRef(MutationRef::SetValue, LiteralStringRef("KeyABCDE"), LiteralStringRef("SomeValu"))); |
| 394 | tr.mutations.push_back_deep( |
| 395 | batchArena, |
| 396 | MutationRef(MutationRef::ClearRange, LiteralStringRef("BeginKey"), LiteralStringRef("EndKeyAB"))); |
| 397 | } |
| 398 | |
| 399 | build += timer() - tstart; |
| 400 | |
| 401 | tstart = timer(); |
| 402 | |
| 403 | BinaryWriter wr(IncludeVersion()); |
| 404 | wr << batch; |
| 405 | |
| 406 | bytes += wr.getLength(); |
| 407 | |
| 408 | serialize += timer() - tstart; |
| 409 | |
| 410 | for (int i = 0; i < 1; i++) { |
| 411 | tstart = timer(); |
| 412 | Arena arena; |
| 413 | StringRef data(arena, StringRef((const uint8_t*)wr.getData(), wr.getLength())); |
| 414 | copy += timer() - tstart; |
| 415 | |
| 416 | tstart = timer(); |
| 417 | ArenaReader rd(arena, data, IncludeVersion()); |
| 418 | VectorRef<CommitTransactionRef> batch2; |
| 419 | rd >> arena >> batch2; |
| 420 | |
| 421 | deserialize += timer() - tstart; |
| 422 | } |
| 423 | |
| 424 | tstart = timer(); |
| 425 | } |
| 426 | deallocate += timer() - tstart; |
| 427 | } |
| 428 | double elapsed = (timer() - testBegin); |
| 429 | printf("Test speed: %0.1f MB/sec (%0.0f/sec)\n", bytes / 1e6 / elapsed, 1000000 / elapsed); |
| 430 | printf(" Build: %0.1f MB/sec\n", bytes / 1e6 / build); |
| 431 | printf(" Serialize: %0.1f MB/sec\n", bytes / 1e6 / serialize); |
| 432 | printf(" Copy: %0.1f MB/sec\n", bytes / 1e6 / copy); |
nothing calls this directly
no test coverage detected