| 362 | } |
| 363 | |
| 364 | double compressLinearSearch() { |
| 365 | const int count = 1000000; |
| 366 | uint64_t *buffer = static_cast<uint64_t*>(malloc(count*sizeof(uint64_t))); |
| 367 | |
| 368 | srand(0); |
| 369 | for (int i = 0; i < count; i++) { |
| 370 | buffer[i] = 1UL << (rand()%64); |
| 371 | } |
| 372 | |
| 373 | int sumOfBytes = 0; |
| 374 | uint64_t start = Cycles::rdtsc(); |
| 375 | for (int i = 0; i < count; ++i) { |
| 376 | int numBytes; |
| 377 | uint64_t val = buffer[i]; |
| 378 | |
| 379 | if (val < (1UL << 8)) { |
| 380 | numBytes = 1; |
| 381 | } else if (val < (1UL << 16)) { |
| 382 | numBytes = 2; |
| 383 | } else if (val < (1UL << 24)) { |
| 384 | numBytes = 3; |
| 385 | } else if (val < (1UL << 32)) { |
| 386 | numBytes = 4; |
| 387 | } else if (val < (1UL << 40)) { |
| 388 | numBytes = 5; |
| 389 | } else if (val < (1UL << 48)) { |
| 390 | numBytes = 6; |
| 391 | } else if (val < (1UL << 56)) { |
| 392 | numBytes = 7; |
| 393 | } else { |
| 394 | numBytes = 8; |
| 395 | } |
| 396 | |
| 397 | sumOfBytes += numBytes; |
| 398 | } |
| 399 | uint64_t stop = Cycles::rdtsc(); |
| 400 | |
| 401 | discard(&sumOfBytes); |
| 402 | |
| 403 | free(buffer); |
| 404 | return Cycles::toSeconds(stop - start)/count; |
| 405 | } |
| 406 | |
| 407 | double delayInBenchmark() { |
| 408 | int count = 1000000; |