Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
benchmark-test.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <iostream>
18 #include <gtest/gtest.h>
19 
20 #include "common/object-pool.h"
21 #include "util/benchmark.h"
22 #include "util/cpu-info.h"
23 
24 #include "common/names.h"
25 
26 // This is not much of a test but demonstrates how to use the Benchmark
27 // utility.
28 namespace impala {
29 
30 struct MemcpyData {
31  char* src;
32  char* dst;
33  int size;
34 };
35 
36 // Utility class to expose private functions for testing
38  public:
39  static double Measure(Benchmark::BenchmarkFunction fn, void* data) {
40  return Benchmark::Measure(fn, data);
41  };
42 };
43 
44 void TestFunction(int batch_size, void* d) {
45  MemcpyData* data = reinterpret_cast<MemcpyData*>(d);
46  for (int i = 0; i < batch_size; ++i) {
47  memcpy(data->dst, data->src, data->size);
48  }
49 }
50 
52  MemcpyData data;
53  data.src = reinterpret_cast<char*>(malloc(128));
54  data.dst = reinterpret_cast<char*>(malloc(128));
55 
56  data.size = 16;
57  double rate_copy_16 = BenchmarkTest::Measure(TestFunction, &data);
58 
59  data.size = 128;
60  double rate_copy_128 = BenchmarkTest::Measure(TestFunction, &data);
61 
62  cout << "Rate 16 Byte: " << rate_copy_16 << endl;
63  cout << "Rate 128 Byte: " << rate_copy_128 << endl;
64 
65  ASSERT_LT(rate_copy_128, rate_copy_16);
66 
67  free(data.src);
68  free(data.dst);
69 }
70 
71 }
72 
73 int main(int argc, char **argv) {
75  ::testing::InitGoogleTest(&argc, argv);
76  return RUN_ALL_TESTS();
77 }
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
std::string Measure()
Runs all the benchmarks and returns the result in a formatted string.
Definition: benchmark.cc:83
int main(int argc, char **argv)
void(* BenchmarkFunction)(int iters, void *)
Definition: benchmark.h:39
static double Measure(Benchmark::BenchmarkFunction fn, void *data)
void TestFunction(int batch_size, void *d)
static void Init()
Initialize CpuInfo.
Definition: cpu-info.cc:75