static void BM_pthread_once(int iters) { StopBenchmarkTiming(); pthread_once_t once = PTHREAD_ONCE_INIT; pthread_once(&once, DummyPthreadOnceInitFunction); StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { pthread_once(&once, DummyPthreadOnceInitFunction); } StopBenchmarkTiming(); }
static void BM_pthread_mutex_lock_RECURSIVE(int iters) { StopBenchmarkTiming(); pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); } StopBenchmarkTiming(); }
static void BM_memset(int iters, int nbytes) { StopBenchmarkTiming(); char* dst = new char[nbytes]; StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { memset(dst, 0, nbytes); } StopBenchmarkTiming(); SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(nbytes)); delete[] dst; }
static void BM_pthread_getspecific(int iters) { StopBenchmarkTiming(); pthread_key_t key; pthread_key_create(&key, NULL); StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { pthread_getspecific(key); } StopBenchmarkTiming(); pthread_key_delete(key); }
static void BM_memmove(int iters, int nbytes) { StopBenchmarkTiming(); char* buf = new char[nbytes + 64]; memset(buf, 'x', nbytes + 64); StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { memmove(buf, buf + 1, nbytes); // Worst-case overlap. } StopBenchmarkTiming(); SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(nbytes)); delete[] buf; }
static void BM_property_serial(int iters, int nprops) { StopBenchmarkTiming(); LocalPropertyTestState pa(nprops); if (!pa.valid) return; srandom(iters * nprops); const prop_info** pinfo = new const prop_info*[iters]; for (int i = 0; i < iters; i++) { pinfo[i] = __system_property_find(pa.names[random() % nprops]); } // StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { StartBenchmarkTiming(); __system_property_serial(pinfo[i]); StopBenchmarkTimingWithStd(); } // StopBenchmarkTiming(); delete[] pinfo; }
static void BM_strlen(int iters, int nbytes) { StopBenchmarkTiming(); char* s = new char[nbytes]; memset(s, 'x', nbytes); s[nbytes - 1] = 0; StartBenchmarkTiming(); volatile int c __attribute__((unused)) = 0; for (int i = 0; i < iters; i++) { c += strlen(s); } StopBenchmarkTiming(); SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(nbytes)); delete[] s; }
/* * Measure the time it takes to submit the android logging call using * discrete acquisition under light load. Expect this to be a dozen or so * syscall periods (40us). */ static void BM_log_overhead(int iters) { for (int i = 0; i < iters; ++i) { StartBenchmarkTiming(); __android_log_print(ANDROID_LOG_INFO, "BM_log_overhead", "%d", i); StopBenchmarkTiming(); usleep(1000); } }
static void BM_memcmp(int iters, int nbytes) { StopBenchmarkTiming(); char* src = new char[nbytes]; char* dst = new char[nbytes]; memset(src, 'x', nbytes); memset(dst, 'x', nbytes); StartBenchmarkTiming(); volatile int c __attribute__((unused)) = 0; for (int i = 0; i < iters; i++) { c += memcmp(dst, src, nbytes); } StopBenchmarkTiming(); SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(nbytes)); delete[] src; delete[] dst; }
static void BM_unistd_gettid_syscall(int iters) { StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { syscall(__NR_gettid); } StopBenchmarkTiming(); }
/* * Measure the time it takes for __android_log_is_loggable. */ static void BM_is_loggable(int iters) { StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { __android_log_is_loggable(ANDROID_LOG_WARN, "logd", ANDROID_LOG_VERBOSE); } StopBenchmarkTiming(); }
static void BM_unistd_gettid(int iters) { StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { gettid_fp(); } StopBenchmarkTiming(); }
/* * Measure the fastest rate we can stuff print messages into the log * at high pressure. Expect this to be less than double the process wakeup * time (2ms?) */ static void BM_log_maximum(int iters) { StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { __android_log_print(ANDROID_LOG_INFO, "BM_log_maximum", "%d", i); } StopBenchmarkTiming(); }
static void BM_pthread_self(int iters) { StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { pthread_self_fp(); } StopBenchmarkTiming(); }
void BM_math_sin_fast::Run(int iters) { StartBenchmarkTiming(); d = 1.0; for (int i = 0; i < iters; ++i) { d += sin(d); } StopBenchmarkTiming(); }
/* * Measure the fastest rate we can reliabley stuff print messages into * the log at high pressure. Expect this to be less than double the process * wakeup time (2ms?) */ static void BM_log_maximum_retry(int iters) { StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { LOG_FAILURE_RETRY( __android_log_print(ANDROID_LOG_INFO, "BM_log_maximum_retry", "%d", i)); } StopBenchmarkTiming(); }
void BM_math_fpclassify::Run(int iters, double value) { StartBenchmarkTiming(); d = 0.0; v = value; for (int i = 0; i < iters; ++i) { d += fpclassify(v); } StopBenchmarkTiming(); }
void BM_math_isinf::Run(int iters, double value) { StartBenchmarkTiming(); d = 0.0; v = value; for (int i = 0; i < iters; ++i) { d += (isinf)(v); } StopBenchmarkTiming(); }
static void BM_math_logb(int iters) { StartBenchmarkTiming(); d = 0.0; v = 1234.0; for (int i = 0; i < iters; ++i) { d += logb(v); } StopBenchmarkTiming(); }
static void BM_math_sqrt(int iters) { StartBenchmarkTiming(); d = 0.0; v = 2.0; for (int i = 0; i < iters; ++i) { d += sqrt(v); } StopBenchmarkTiming(); }
void BM_math_sin_feupdateenv::Run(int iters) { StartBenchmarkTiming(); d = 1.0; for (int i = 0; i < iters; ++i) { fenv_t __libc_save_rm; feholdexcept(&__libc_save_rm); fesetround(FE_TONEAREST); d += sin(d); feupdateenv(&__libc_save_rm); } StopBenchmarkTiming(); }
static void BM_property_find(int iters, int nprops) { StopBenchmarkTiming(); LocalPropertyTestState pa(nprops); if (!pa.valid) return; srandom(iters * nprops); // StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { StartBenchmarkTiming(); __system_property_find(pa.names[random() % nprops]); StopBenchmarkTimingWithStd(); } // StopBenchmarkTiming(); }
static void BM_property_get(int iters, int nprops) { StopBenchmarkTiming(); LocalPropertyTestState pa(nprops); char value[PROP_VALUE_MAX]; if (!pa.valid) return; srandom(iters * nprops); // StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { StartBenchmarkTiming(); __system_property_get(pa.names[random() % nprops], value); StopBenchmarkTimingWithStd(); } // StopBenchmarkTiming(); }
/* * Measure the time it takes to submit the android logging call using * discrete acquisition under light load. Expect this to be a pair of * syscall periods (2us). */ static void BM_clock_overhead(int iters) { for (int i = 0; i < iters; ++i) { StartBenchmarkTiming(); StopBenchmarkTiming(); } }
/* * Measure the time it takes for the logd posting call to make it into * the logs. Expect this to be less than double the process wakeup time (2ms). */ static void BM_log_delay(int iters) { pid_t pid = getpid(); struct logger_list * logger_list = android_logger_list_open(LOG_ID_EVENTS, O_RDONLY, 0, pid); if (!logger_list) { fprintf(stderr, "Unable to open events log: %s\n", strerror(errno)); exit(EXIT_FAILURE); } signal(SIGALRM, caught_delay); alarm(alarm_time); StartBenchmarkTiming(); for (int i = 0; i < iters; ++i) { log_time ts(CLOCK_REALTIME); LOG_FAILURE_RETRY( android_btWriteLog(0, EVENT_TYPE_LONG, &ts, sizeof(ts))); for (;;) { log_msg log_msg; int ret = android_logger_list_read(logger_list, &log_msg); alarm(alarm_time); if (ret <= 0) { iters = i; break; } if ((log_msg.entry.len != (4 + 1 + 8)) || (log_msg.id() != LOG_ID_EVENTS)) { continue; } char* eventData = log_msg.msg(); if (eventData[4] != EVENT_TYPE_LONG) { continue; } log_time tx(eventData + 4 + 1); if (ts != tx) { if (0xDEADBEEFA55A5AA6ULL == caught_convert(eventData + 4 + 1)) { iters = i; break; } continue; } break; } } signal(SIGALRM, SIG_DFL); alarm(0); StopBenchmarkTiming(); android_logger_list_free(logger_list); }
void BM_stdio_fopen_fgets_fclose_no_locking::Run(int iters) { StartBenchmarkTiming(); FopenFgetsFclose(iters, true); StopBenchmarkTiming(); }