Skip to content

Commit 1f5be4c

Browse files
committed
- improve precision of calculations (benchmark results)
- 2 small bugfixes.
1 parent 91201a2 commit 1f5be4c

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

client.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,41 +1336,37 @@ void run_stats::summarize(totals& result) const
13361336
}
13371337

13381338
unsigned long int test_duration_usec = ts_diff(m_start_time, m_end_time);
1339-
unsigned int test_duration_sec = test_duration_usec / 1000000;
13401339

13411340
result.m_ops_set = totals.m_ops_set;
13421341
result.m_ops_get = totals.m_ops_get;
13431342
result.m_ops = totals.m_ops_get + totals.m_ops_set;
13441343
result.m_bytes = totals.m_bytes_get + totals.m_bytes_set;
13451344

1346-
if (test_duration_sec == 0)
1347-
test_duration_sec = 1;
1348-
1349-
result.m_ops_sec_set = (double) totals.m_ops_set / test_duration_sec;
1345+
result.m_ops_sec_set = (double) totals.m_ops_set / test_duration_usec * 1000000;
13501346
if (totals.m_ops_set > 0) {
13511347
result.m_latency_set = (double) (totals.m_total_set_latency / totals.m_ops_set) / 1000;
13521348
} else {
13531349
result.m_latency_set = 0;
13541350
}
1355-
result.m_bytes_sec_set = (double) ((totals.m_bytes_set / 1024) / test_duration_sec);
1351+
result.m_bytes_sec_set = (totals.m_bytes_set / 1024.0) / test_duration_usec * 1000000;
13561352

1357-
result.m_ops_sec_get = (double) totals.m_ops_get / test_duration_sec;
1353+
result.m_ops_sec_get = (double) totals.m_ops_get / test_duration_usec * 1000000;
13581354
if (totals.m_ops_get > 0) {
13591355
result.m_latency_get = (double) (totals.m_total_get_latency / totals.m_ops_get) / 1000;
13601356
} else {
13611357
result.m_latency_get = 0;
13621358
}
1363-
result.m_bytes_sec_get = (double) ((totals.m_bytes_get / 1024) / test_duration_sec);
1364-
result.m_hits_sec = (double) totals.m_get_hits / test_duration_sec;
1365-
result.m_misses_sec = (double) totals.m_get_misses / test_duration_sec;
1359+
result.m_bytes_sec_get = (totals.m_bytes_get / 1024.0) / test_duration_usec * 1000000;
1360+
result.m_hits_sec = (double) totals.m_get_hits / test_duration_usec * 1000000;
1361+
result.m_misses_sec = (double) totals.m_get_misses / test_duration_usec * 1000000;
13661362

1367-
result.m_ops_sec = (double) result.m_ops / test_duration_sec;
1363+
result.m_ops_sec = (double) result.m_ops / test_duration_usec * 1000000;
13681364
if (result.m_ops > 0) {
13691365
result.m_latency = (double) ((totals.m_total_get_latency + totals.m_total_set_latency) / result.m_ops) / 1000;
13701366
} else {
13711367
result.m_latency = 0;
13721368
}
1373-
result.m_bytes_sec = (double) ((result.m_bytes / 1024) / test_duration_sec);
1369+
result.m_bytes_sec = (result.m_bytes / 1024.0) / test_duration_usec * 1000000;
13741370
}
13751371

13761372
void run_stats::print(FILE *out, bool histogram)

memtier_benchmark.cpp

100755100644
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ run_stats run_benchmark(int run_id, benchmark_config* cfg, object_generator* obj
725725
unsigned long int bytes_sec = 0;
726726
double avg_latency = 0;
727727
if (duration > 1000000) {
728-
ops_sec = (total_ops / (duration / 1000000));
729-
bytes_sec = (total_bytes / (duration / 1000000));
728+
ops_sec = (long)( (double)total_ops / duration * 1000000);
729+
bytes_sec = (long)( (double)total_bytes / duration * 1000000);
730730
avg_latency = ((double) total_latency / 1000 / total_ops) ;
731731
}
732732

@@ -979,13 +979,13 @@ int main(int argc, char *argv[])
979979
run_stats* worst = NULL;
980980
run_stats* best = NULL;
981981
for (std::vector<run_stats>::iterator i = all_stats.begin(); i != all_stats.end(); i++) {
982-
unsigned int secs = (i->get_duration_usec() / 1000);
983-
unsigned int ops_sec = (i->get_total_ops() / (secs > 0 ? secs : 1)) * 1000;
984-
if (ops_sec < min_ops_sec) {
982+
unsigned long usecs = i->get_duration_usec();
983+
unsigned int ops_sec = (int)(((double)i->get_total_ops() / (usecs > 0 ? usecs : 1)) * 1000000);
984+
if (ops_sec < min_ops_sec || worst == NULL) {
985985
min_ops_sec = ops_sec;
986986
worst = &(*i);
987987
}
988-
if (ops_sec > max_ops_sec) {
988+
if (ops_sec > max_ops_sec || best == NULL) {
989989
max_ops_sec = ops_sec;
990990
best = &(*i);
991991
}

obj_gen.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ int gaussian_noise::gaussian_distribution_range(double stddev, double median, in
104104
{
105105
int len = max-min;
106106
double val;
107-
if (median==0)
108-
median = len/2.0+min + 0.5;
109-
if (stddev==0)
110-
stddev = len/6.0;
111-
assert(median>min && median<max);
107+
if (median == 0)
108+
median = len / 2.0 + min + 0.5;
109+
if (stddev == 0)
110+
stddev = len / 6.0;
111+
assert(median > min && median < max);
112112
do {
113113
val = gaussian_distribution(stddev) + median;
114-
} while(val<min || val>max+1);
114+
} while(val < min || val > max + 1);
115115
return val;
116116
}
117117

@@ -124,6 +124,8 @@ object_generator::object_generator() :
124124
m_key_prefix(NULL),
125125
m_key_min(0),
126126
m_key_max(0),
127+
m_key_stddev(0),
128+
m_key_median(0),
127129
m_value_buffer(NULL),
128130
m_random_fd(-1)
129131
{
@@ -144,6 +146,7 @@ object_generator::object_generator(const object_generator& copy) :
144146
m_key_min(copy.m_key_min),
145147
m_key_max(copy.m_key_max),
146148
m_key_stddev(copy.m_key_stddev),
149+
m_key_median(copy.m_key_median),
147150
m_value_buffer(NULL),
148151
m_random_fd(-1)
149152

0 commit comments

Comments
 (0)