Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <jni.h>
  2. #include <string>
  3. #include <vector>
  4. #include <ctime>
  5. #include <android/log.h>
  6. #include <unordered_map>
  7.  
  8. typedef struct record {
  9. int year;
  10. int month;
  11. int day;
  12. double temperature;
  13. } Record;
  14.  
  15. inline void group(std::vector<Record> &records, std::unordered_map<std::string, std::vector<Record>> &map) {
  16. for (const auto &record : records) {
  17. map[std::to_string(record.year) + " " + std::to_string(record.month)].push_back(record);
  18. }
  19. }
  20.  
  21. inline int64_t nanoTime() {
  22. struct timespec now{};
  23. clock_gettime(CLOCK_MONOTONIC, &now);
  24. return (int64_t) now.tv_sec * 1000000000LL + now.tv_nsec;
  25. }
  26.  
  27. inline int64_t measureNanoTime(const std::function<void()> &body) {
  28. int64_t start = nanoTime();
  29. body();
  30. int64_t end = nanoTime();
  31. return end - start;
  32. }
  33.  
  34. extern "C" JNIEXPORT void JNICALL
  35. Java_eu_lepicekmichal_android_1sdk_1ndk_MainActivity_dataProcessingTest(
  36. JNIEnv *env,
  37. jobject,
  38. ) {
  39. std::vector<Record> records;
  40. std::unordered_map<std::string, std::vector<Record>> map;
  41.  
  42. std::ios::sync_with_stdio(false);
  43.  
  44. int64_t groupTime = measureNanoTime([&]() -> void { group(records, map); });
  45.  
  46. __android_log_print(ANDROID_LOG_DEBUG, __FUNCTION__, "GROUP: %li", groupTime);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement