File: ondiskspeedtest.cc

package info (click to toggle)
wvstreams 4.0.2-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,420 kB
  • ctags: 6,518
  • sloc: cpp: 52,544; sh: 5,770; ansic: 810; makefile: 461; tcl: 114; perl: 18
file content (88 lines) | stat: -rw-r--r-- 2,047 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#include <time.h>
#include <wvautoconf.h>
#if defined(WITH_QDBM) || defined(WITH_BDB)
#include <wvondiskhash.h>
#endif
#include <wvlog.h>
#include <wvstring.h>
#include <wvtimeutils.h>

#if defined(WITH_QDBM) || defined(WITH_BDB)
template <class HashType>
void SpeedDemon(WvStringParm name, int max)
{
    WvLog log("SpeedDemon");

    unlink("test.db");
    WvOnDiskHash<int, int, HashType> testhash("test.db");
    log("---------------------------------\n");
    log("Testing %s with %s records...\n", name, max);

    WvTime start = wvtime();
    for (int i = 0; i < max; ++i)
        testhash.add(i, i);

    log("    sequential write:    %s ms\n",
            msecdiff(wvtime(), start));
    start = wvtime();

    for (int i = 0; i < max; ++i)
    {
        int r = random() % max;
        testhash.add(r, r, true);
    }

    log("    random write:        %s ms\n",
            msecdiff(wvtime(), start));
    start = wvtime();

    for (int i = 0; i < max; ++i)
    {
        if (testhash.find(i) != i)
            log(WvLog::Error, "Error!!");
    }

    log("    sequential read:     %s ms\n",
            msecdiff(wvtime(), start));
    start = wvtime();

    for (int i = 0; i < max; ++i)
    {
        int r = random() % max;
        if (testhash.find(r) != r)
            log(WvLog::Error, "Error!!");
    }

    log("    random read:         %s ms\n",
            msecdiff(wvtime(), start));
    start = wvtime();

    typename WvOnDiskHash<int, int, HashType>::Iter i(testhash);
    for (i.rewind(); i.next(); ) {}

    log("    full iteration:      %s ms\n",
            msecdiff(wvtime(), start));
}
#endif

int main(int argc, char **argv)
{
    int numrecords = 25000;
    if (argc > 1 && atoi(argv[1]))
        numrecords = atoi(argv[1]);

    srandom(time(0));

#ifdef WITH_BDB
    SpeedDemon<WvBdbHash>("BDB hash", numrecords);
#else
    fprintf(stderr, "Not testing BDB hash!\n");
#endif

#ifdef WITH_QDBM
    SpeedDemon<WvQdbmHash>("QDBM hash", numrecords);
#else
    fprintf(stderr, "Not testing QDBM hash!\n");
#endif
}