Skip to content

Commit

Permalink
Added simple decode benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nong Li committed May 20, 2014
1 parent 0959d2a commit 722c751
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ add_library(Example STATIC

add_executable(compute_stats compute_stats.cc)
target_link_libraries(compute_stats Parquet Example ThriftParquet thriftstatic)

add_executable(decode_benchmark decode_benchmark.cc)
target_link_libraries(decode_benchmark Parquet Example ThriftParquet thriftstatic rt)
74 changes: 74 additions & 0 deletions example/decode_benchmark.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <parquet/parquet.h>
#include <iostream>
#include <stdio.h>

#include "example_util.h"
#include "encodings.h"

using namespace parquet;
using namespace parquet_cpp;
using namespace std;

class StopWatch {
public:
StopWatch() {
}

void Start() {
clock_gettime(CLOCK_MONOTONIC, &start_);
}

// Returns time in nanoseconds.
uint64_t Stop() {
timespec end;
clock_gettime(CLOCK_MONOTONIC, &end);
return (end.tv_sec - start_.tv_sec) * 1000L * 1000L * 1000L +
(end.tv_nsec - start_.tv_nsec);
}

private:
timespec start_;
};

uint64_t TestPlainIntEncoding(const uint8_t* data, int num_values, int batch_size) {
uint64_t result = 0;
PlainDecoder decoder(NULL);
decoder.SetData(num_values, data, num_values * sizeof(int32_t));
int32_t values[batch_size];
for (int i = 0; i < num_values;) {
int n = decoder.GetInt32(values, batch_size);
for (int j = 0; j < n; ++j) {
result += values[j];
}
i += n;
}
return result;
}

#define TEST(NAME, FN, DATA, BATCH_SIZE)\
sw.Start();\
for (int i = 0; i < NUM_ITERS; ++i) {\
FN(reinterpret_cast<uint8_t*>(&DATA[0]), NUM_VALUES, BATCH_SIZE);\
}\
elapsed = sw.Stop();\
printf("%s rate (batch size = %2d): %0.2f per second.\n",\
NAME, BATCH_SIZE, mult / elapsed);

int main(int argc, char** argv) {
StopWatch sw;
uint64_t elapsed = 0;

const int NUM_VALUES = 1024 * 1024;
const int NUM_ITERS = 10;
const double mult = NUM_VALUES * 1000. * 1000. * 1000. * NUM_ITERS;

vector<int32_t> plain_int_data;
plain_int_data.resize(NUM_VALUES);

TEST("Plain decoder", TestPlainIntEncoding, plain_int_data, 1);
TEST("Plain decoder", TestPlainIntEncoding, plain_int_data, 16);
TEST("Plain decoder", TestPlainIntEncoding, plain_int_data, 32);
TEST("Plain decoder", TestPlainIntEncoding, plain_int_data, 64);

return 0;
}
2 changes: 1 addition & 1 deletion src/encodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PlainDecoder : public Decoder {
int GetValues(void* buffer, int max_values, int byte_size) {
max_values = std::min(max_values, num_values_);
int size = max_values * byte_size;
if (size < len_) ParquetException::EofException();
if (len_ < size) ParquetException::EofException();
memcpy(buffer, data_, size);
data_ += size;
len_ -= size;
Expand Down

0 comments on commit 722c751

Please sign in to comment.