Skip to content

Commit

Permalink
Use thread time instead of process time
Browse files Browse the repository at this point in the history
Fixes problem with measuring performance on Arm platform for
reasons unknown.
  • Loading branch information
perim committed Nov 19, 2023
1 parent 5a710e0 commit 2891240
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static inline constexpr void lfsr_next(uint64_t& state, uint32_t tap) { const ui
static inline constexpr __attribute__((const)) uint64_t lfsr_init(uint64_t state, uint32_t bits) { return fastrange(splitmix64(state), 1, 1 << bits); }

/// CPU time measurement
static inline uint64_t cpu_gettime() { struct timespec t; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t); return ((uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec); }
static inline uint64_t cpu_gettime() { struct timespec t; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t); return ((uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec); }

// -- 2^10 fractional math --
// Numbers based around 100 are not good to do fast math on, so we can use to a 2^10 system instead. We call these "perten" values. Math using
Expand Down
16 changes: 8 additions & 8 deletions tests/perf_table_rolls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ int main(int argc, char **argv)
printf("Size of 5000 entry LRT=%u LS=%u\n", (unsigned)(sizeof(lrt5k) + lrt5k.table.size() * sizeof(*lrt5k.table.data())), (unsigned)sizeof(ls5k));

t1 = cpu_gettime();
for (int i = 0; i < 4000; i++) lrt5k.roll();
for (int i = 0; i < 40000; i++) lrt5k.roll();
t2 = cpu_gettime();
printf("%-30s %'12" PRIu64 "\n", "LRT 4k rolls 5k alloc", t2 - t1);
printf("%-30s %'12" PRIu64 "\n", "LRT 40k rolls 5k alloc", t2 - t1);

t1 = cpu_gettime();
for (int i = 0; i < 4000; i++) ls5k.roll();
for (int i = 0; i < 40000; i++) ls5k.roll();
t2 = cpu_gettime();
printf("%-30s %'12" PRIu64 "\n", "LS 4k rolls 5k alloc", t2 - t1);
printf("%-30s %'12" PRIu64 "\n", "LS 40k rolls 5k alloc", t2 - t1);

const std::vector<int> w5k(5000, 1);
roll_table rt5k(s, w5k);
t1 = cpu_gettime();
for (int i = 0; i < 4000; i++) rt5k.roll();
for (int i = 0; i < 40000; i++) rt5k.roll();
t2 = cpu_gettime();
printf("%-30s %'12" PRIu64 "\n", "RT 4k rolls 5k alloc", t2 - t1);
printf("%-30s %'12" PRIu64 "\n", "RT 40k rolls 5k alloc", t2 - t1);

linear_series ls4k(s, 4096-1);
t1 = cpu_gettime();
for (int i = 0; i < 4000; i++) ls4k.roll();
for (int i = 0; i < 40000; i++) ls4k.roll();
t2 = cpu_gettime();
printf("%-30s %'12" PRIu64 "\n", "LS 4k rolls 4k-1 alloc", t2 - t1);
printf("%-30s %'12" PRIu64 "\n", "LS 40k rolls 4k-1 alloc", t2 - t1);

std::vector<int> weights(200);
for (int i = 0; i < 200; i++) weights[i] = 100 + i*50;
Expand Down

0 comments on commit 2891240

Please sign in to comment.