localtime_r(3) should act as if it calls tzset(3).
See code comment.
Bug: http://b/31339449
Test: ran tests & benchmarks
Change-Id: I6b6a63750ef41664dc4698207e6a53e77cc28cdf
diff --git a/benchmarks/time_benchmark.cpp b/benchmarks/time_benchmark.cpp
index 4a5c2da..c90dfad 100644
--- a/benchmarks/time_benchmark.cpp
+++ b/benchmarks/time_benchmark.cpp
@@ -40,7 +40,7 @@
static void BM_time_gettimeofday(benchmark::State& state) {
timeval tv;
while (state.KeepRunning()) {
- gettimeofday(&tv, NULL);
+ gettimeofday(&tv, nullptr);
}
}
BENCHMARK(BM_time_gettimeofday);
@@ -48,14 +48,31 @@
void BM_time_gettimeofday_syscall(benchmark::State& state) {
timeval tv;
while (state.KeepRunning()) {
- syscall(__NR_gettimeofday, &tv, NULL);
+ syscall(__NR_gettimeofday, &tv, nullptr);
}
}
BENCHMARK(BM_time_gettimeofday_syscall);
void BM_time_time(benchmark::State& state) {
while (state.KeepRunning()) {
- time(NULL);
+ time(nullptr);
}
}
BENCHMARK(BM_time_time);
+
+void BM_time_localtime(benchmark::State& state) {
+ time_t t = time(nullptr);
+ while (state.KeepRunning()) {
+ localtime(&t);
+ }
+}
+BENCHMARK(BM_time_localtime);
+
+void BM_time_localtime_r(benchmark::State& state) {
+ time_t t = time(nullptr);
+ while (state.KeepRunning()) {
+ struct tm tm;
+ localtime_r(&t, &tm);
+ }
+}
+BENCHMARK(BM_time_localtime_r);