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
89
90
91
92
93
94
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/log/log.h>
LOG_SETUP("bufferwriter_bm");
#include <vespa/vespalib/testkit/testapp.h>
#include <iostream>
#include "work.h"
#include <vespa/searchlib/util/drainingbufferwriter.h>
using search::DrainingBufferWriter;
double getTime() { return fastos::TimeStamp(fastos::ClockSystem::now()).sec(); }
constexpr size_t million = 1000000;
enum class WorkFuncDispatch
{
DIRECT,
LAMBDA,
FUNCTOR,
FUNCTOR2
};
template <typename T>
void
callWork(size_t size, WorkFuncDispatch dispatch)
{
std::vector<T> foo;
DrainingBufferWriter writer;
foo.resize(size);
std::cout << "will write " << size << " elements of size " << sizeof(T) <<
std::endl;
double before = getTime();
switch (dispatch) {
case WorkFuncDispatch::DIRECT:
work(foo, writer);
break;
case WorkFuncDispatch::LAMBDA:
workLambda(foo, writer);
break;
case WorkFuncDispatch::FUNCTOR:
workFunctor(foo, writer);
break;
case WorkFuncDispatch::FUNCTOR2:
workFunctor2(foo, writer);
break;
default:
abort();
}
double after = getTime();
double delta = (after - before);
double writeSpeed = writer.getBytesWritten() / delta;
EXPECT_GREATER(writeSpeed, 1000);
std::cout << "written is " << writer.getBytesWritten() << std::endl;
std::cout << "time used is " << (delta * 1000.0) << " ms" << std::endl;
std::cout << "write speed is " << writeSpeed << std::endl;
}
void
callWorks(WorkFuncDispatch dispatch)
{
callWork<char>(million * 1000, dispatch);
callWork<short>(million * 500, dispatch);
callWork<int>(million * 250, dispatch);
callWork<long>(million * 125, dispatch);
}
TEST("simple bufferwriter speed test")
{
callWorks(WorkFuncDispatch::DIRECT);
}
TEST("lambda func bufferwriter speed test")
{
callWorks(WorkFuncDispatch::LAMBDA);
}
TEST("functor bufferwriter speed test")
{
callWorks(WorkFuncDispatch::FUNCTOR);
}
TEST("functor2 bufferwriter speed test")
{
callWorks(WorkFuncDispatch::FUNCTOR2);
}
TEST_MAIN()
{
TEST_RUN_ALL();
}
|