| 596 | } |
| 597 | |
| 598 | double arrayStructCast() |
| 599 | { |
| 600 | const int count = 1000000; |
| 601 | char *baseBuffer = static_cast<char*>(malloc(count*4*sizeof(uint64_t))); |
| 602 | char *buffer = baseBuffer; |
| 603 | |
| 604 | uint64_t start = Cycles::rdtsc(); |
| 605 | for (int i = 0; i < count; ++i) { |
| 606 | struct Quadnums { |
| 607 | uint64_t num1; |
| 608 | uint64_t num2; |
| 609 | uint64_t num3; |
| 610 | uint64_t num4; |
| 611 | }; |
| 612 | |
| 613 | struct Quadnums *nums = reinterpret_cast<struct Quadnums*>(buffer); |
| 614 | nums->num1 = 1; |
| 615 | nums->num2 = 2; |
| 616 | nums->num3 = 3; |
| 617 | nums->num4 = 4; |
| 618 | buffer += sizeof(struct Quadnums); |
| 619 | } |
| 620 | uint64_t stop = Cycles::rdtsc(); |
| 621 | |
| 622 | free(baseBuffer); |
| 623 | return Cycles::toSeconds(stop - start)/count; |
| 624 | } |
| 625 | |
| 626 | // Measure the time to create and delete an entry in a small |
| 627 | // map. |