Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <jni.h>
- #include <string>
- #include <vector>
- #include <ctime>
- #include <android/log.h>
- #include <unordered_map>
- typedef struct record {
- int year;
- int month;
- int day;
- double temperature;
- } Record;
- inline void group(std::vector<Record> &records, std::unordered_map<std::string, std::vector<Record>> &map) {
- for (const auto &record : records) {
- map[std::to_string(record.year) + " " + std::to_string(record.month)].push_back(record);
- }
- }
- inline int64_t nanoTime() {
- struct timespec now{};
- clock_gettime(CLOCK_MONOTONIC, &now);
- return (int64_t) now.tv_sec * 1000000000LL + now.tv_nsec;
- }
- inline int64_t measureNanoTime(const std::function<void()> &body) {
- int64_t start = nanoTime();
- body();
- int64_t end = nanoTime();
- return end - start;
- }
- extern "C" JNIEXPORT void JNICALL
- Java_eu_lepicekmichal_android_1sdk_1ndk_MainActivity_dataProcessingTest(
- JNIEnv *env,
- jobject,
- ) {
- std::vector<Record> records;
- std::unordered_map<std::string, std::vector<Record>> map;
- std::ios::sync_with_stdio(false);
- int64_t groupTime = measureNanoTime([&]() -> void { group(records, map); });
- __android_log_print(ANDROID_LOG_DEBUG, __FUNCTION__, "GROUP: %li", groupTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement