Last active
November 20, 2018 06:49
-
-
Save alendit/41e96c04eb46657dc8bb23549372a2a9 to your computer and use it in GitHub Desktop.
Building 1kk string of 10 chars each in arrow-cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "arrow/builder.h" | |
#include "arrow/array.h" | |
#include <vector> | |
#include <cstdlib> | |
#include <iostream> | |
#include <chrono> | |
#include <cmath> | |
#include <memory> | |
using namespace std; | |
using namespace arrow; | |
char random_char() { | |
auto rnd = ('z' - 'a') * ((double)rand() / RAND_MAX); | |
return 'a' + rnd; | |
} | |
void gen_rand(vector<char>& arr) { | |
for (auto& el : arr) { | |
el = random_char(); | |
} | |
} | |
int main() { | |
constexpr int64_t N = 10'000'000; | |
vector<char> arr; | |
arr.resize(N); | |
gen_rand(arr); | |
StringBuilder builder; | |
if (!builder.Reserve(N / 10).ok()) { | |
throw; | |
} | |
auto start = chrono::high_resolution_clock::now(); | |
for (auto i = arr.begin(), end = arr.end(); i < end; i += 10) { | |
Status s = builder.Append(&*i, 10); | |
if (!s.ok()) { | |
throw; | |
} | |
} | |
shared_ptr<Array> output; | |
Status s = builder.Finish(&output); | |
if (!s.ok()) { | |
throw; | |
} | |
auto end = chrono::high_resolution_clock::now(); | |
chrono::duration<double, milli> duration = end - start; | |
cout << "Built array with " << output->length() << " elements." | |
<< "\n Took " << duration.count() << "ms" << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.10) | |
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/arrow/cpp/cmake_modules") | |
find_package(Arrow) | |
include_directories(${ARROW_INCLUDE_DIR}) | |
MESSAGE( STATUS ${ARROW_INCLUDE_DIR}) | |
add_executable(build_str build_str.cpp) | |
target_link_libraries(build_str ${ARROW_SHARED_LIB}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment