Skip to content

Commit

Permalink
Refactor timing code into sorttimer class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortal committed Nov 1, 2011
1 parent 48a971e commit 9dd6a1f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
10 changes: 1 addition & 9 deletions bench_external_sort_stxxl.cpp
Expand Up @@ -45,16 +45,8 @@ int main(int argc, char **argv) {
v[i] = prng();

STXXL_MSG("Sorting (using " << (memory >> 20) << " MiB of memory)...");
timeval before;
gettimeofday(&before, 0);
sorttimer _(n_records, sizeof(type));
stxxl::sort(v.begin(), v.end(), cmp(), memory);
timeval after;
gettimeofday(&after, 0);

double seconds = after - before;
double MiB = double(n_records * sizeof(type)) / double(1 << 20);

STXXL_MSG("Sorted " << n_records << " elements of size " << sizeof(type) << " (total " << (MiB / 1024) << " GiB) in " << seconds << " seconds, " << (double(n_records) / seconds) << " items/sec " << (MiB / seconds) << " MiB/s");

return 0;
}
Expand Down
24 changes: 7 additions & 17 deletions bench_external_sort_tpie.cpp
@@ -1,10 +1,5 @@
// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
// vi:set ts=4 sts=4 sw=4 noet cino+=(0 :
#include <tpie/tpie.h>
#include <tpie/sort.h>
#include <tpie/stream.h>

#include "common.h"

#ifdef SORTING_MEMORY
// from tpie/test/blocksize2MB.h:
Expand All @@ -19,6 +14,12 @@
#endif
#endif

#include "common.h"

#include <tpie/tpie.h>
#include <tpie/sort.h>
#include <tpie/stream.h>

using namespace tpie;

void sort_test(size_t n, int seed = 42) {
Expand All @@ -30,20 +31,9 @@ void sort_test(size_t n, int seed = 42) {
mystream.write_item(x);
}

timeval before;
gettimeofday(&before, 0);

std::cout << "tpie::ami::sort()" << std::endl;
sorttimer _(n, sizeof(type));
ami::sort(&mystream);
mystream.seek(0);

timeval after;
gettimeofday(&after, 0);

double seconds = after - before;
double MiB = double(n * sizeof(type)) / double(1 << 20);

std::cout << "Sorted " << n << " elements of size " << sizeof(type) << " (total " << (MiB / 1024) << " GiB) in " << seconds << " seconds, " << (double(n) / seconds) << " items/sec " << (MiB / seconds) << " MiB/s" << std::endl;
}


Expand Down
19 changes: 19 additions & 0 deletions common.h
Expand Up @@ -19,3 +19,22 @@ double operator - (const timeval & a, const timeval & b)
return double(sec) + double(usec) / 1000000.;
}

struct sorttimer {
sorttimer(size_t n, size_t size) : n(n), size(size) {
gettimeofday(&before, 0);
}
~sorttimer() {
timeval after;
gettimeofday(&after, 0);

double seconds = after - before;
double MiB = double(n * sizeof(type)) / double(1 << 20);

std::cout << "Sorted " << n << " elements of size " << size << " (total " << (MiB / 1024) << " GiB) in " << seconds << " seconds, " << (double(n) / seconds) << " items/sec " << (MiB / seconds) << " MiB/s" << std::endl;
}
private:
timeval before;
size_t n;
size_t size;
};

0 comments on commit 9dd6a1f

Please sign in to comment.