Skip to content

Commit

Permalink
new api
Browse files Browse the repository at this point in the history
  • Loading branch information
lilothar committed May 30, 2024
1 parent 5298cb5 commit 267bb12
Show file tree
Hide file tree
Showing 110 changed files with 4,699 additions and 4,533 deletions.
2 changes: 1 addition & 1 deletion benchmark/container/btree_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <turbo/random/random.h>
#include <turbo/strings/cord.h>
#include <turbo/strings/str_format.h>
#include <turbo/time/time.h>
#include <turbo/times/time.h>

namespace turbo {
TURBO_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion benchmark/debugging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

carbin_cc_bm(
NAME stacktrace_benchmark
MODULE base
MODULE debugging
SOURCES stacktrace_benchmark.cc
LINKS turbo::turbo benchmark::benchmark benchmark::benchmark_main ${CARBIN_DEPS_LINK}
CXXOPTS ${USER_CXX_FLAGS}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/flags/flag_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <turbo/flags/parse.h>
#include <turbo/flags/reflection.h>
#include <turbo/strings/string_view.h>
#include <turbo/time/time.h>
#include <turbo/times/time.h>
#include <turbo/types/optional.h>
#include <benchmark/benchmark.h>

Expand Down
2 changes: 1 addition & 1 deletion benchmark/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

carbin_cc_bm(
NAME function_type_benchmark
MODULE function
MODULE functional
SOURCES function_type_benchmark.cc
LINKS turbo::turbo benchmark::benchmark benchmark::benchmark_main ${CARBIN_DEPS_LINK}
CXXOPTS ${USER_CXX_FLAGS}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/profile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

carbin_cc_bm(
NAME periodic_sampler_benchmark
MODULE profiling
MODULE profile
SOURCES periodic_sampler_benchmark.cc
LINKS turbo::turbo benchmark::benchmark benchmark::benchmark_main ${CARBIN_DEPS_LINK}
CXXOPTS ${USER_CXX_FLAGS}
Expand Down
6 changes: 3 additions & 3 deletions benchmark/synchronization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@

carbin_cc_bm(
NAME blocking_counter_benchmark
MODULE sync
MODULE synchronization
SOURCES blocking_counter_benchmark.cc
LINKS turbo::turbo benchmark::benchmark benchmark::benchmark_main ${CARBIN_DEPS_LINK}
CXXOPTS ${USER_CXX_FLAGS}
)

carbin_cc_bm(
NAME graphcycles_benchmark
MODULE sync
MODULE synchronization
SOURCES graphcycles_benchmark.cc
LINKS turbo::turbo benchmark::benchmark benchmark::benchmark_main ${CARBIN_DEPS_LINK}
CXXOPTS ${USER_CXX_FLAGS}
)

carbin_cc_bm(
NAME mutex_benchmark
MODULE sync
MODULE synchronization
SOURCES mutex_benchmark.cc
LINKS turbo::turbo benchmark::benchmark benchmark::benchmark_main ${CARBIN_DEPS_LINK}
CXXOPTS ${USER_CXX_FLAGS}
Expand Down
6 changes: 3 additions & 3 deletions benchmark/times/cctz_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <vector>

#include <benchmark/benchmark.h>
#include <turbo/time/cctz/civil_time.h>
#include <turbo/time/cctz/time_zone.h>
#include <turbo/time/cctz/time_zone_impl.h>
#include <turbo/times/cctz/civil_time.h>
#include <turbo/times/cctz/time_zone.h>
#include <turbo/times/cctz/time_zone_impl.h>

namespace {

Expand Down
2 changes: 1 addition & 1 deletion benchmark/times/civil_time_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include <turbo/time/civil_time.h>
#include <turbo/times/civil_time.h>

#include <cstddef>
#include <numeric>
Expand Down
6 changes: 3 additions & 3 deletions benchmark/times/clock_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include <turbo/time/clock.h>
#include <turbo/times/clock.h>

#if !defined(_WIN32)
#include <sys/time.h>
Expand All @@ -31,7 +31,7 @@ namespace {

void BM_Clock_Now_TurboTime(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(turbo::Now());
benchmark::DoNotOptimize(turbo::Time::current_time());
}
}
BENCHMARK(BM_Clock_Now_TurboTime);
Expand All @@ -45,7 +45,7 @@ BENCHMARK(BM_Clock_Now_GetCurrentTimeNanos);

void BM_Clock_Now_TurboTime_ToUnixNanos(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(turbo::ToUnixNanos(turbo::Now()));
benchmark::DoNotOptimize(turbo::ToUnixNanos(turbo::Time::current_time()));
}
}
BENCHMARK(BM_Clock_Now_TurboTime_ToUnixNanos);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/times/duration_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <turbo/base/attributes.h>
#include <turbo/flags/flag.h>
#include <turbo/time/time.h>
#include <turbo/times/time.h>
#include <benchmark/benchmark.h>

TURBO_FLAG(turbo::Duration, turbo_duration_flag_for_benchmark,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/times/format_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <string>

#include <tests/times/test_util.h>
#include <turbo/time/time.h>
#include <turbo/times/time.h>
#include <benchmark/benchmark.h>

namespace {
Expand Down
32 changes: 16 additions & 16 deletions benchmark/times/time_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include <turbo/time/time.h>
#include <turbo/times/time.h>

#if !defined(_WIN32)
#include <sys/time.h>
Expand All @@ -28,7 +28,7 @@
#include <memory>
#include <string>

#include <turbo/time/clock.h>
#include <turbo/times/clock.h>
#include <tests/times/test_util.h>
#include <benchmark/benchmark.h>

Expand All @@ -54,7 +54,7 @@ BENCHMARK(BM_Time_Arithmetic);
//

void BM_Time_Difference(benchmark::State& state) {
turbo::Time start = turbo::Now();
turbo::Time start = turbo::Time::current_time();
turbo::Time end = start + turbo::Nanoseconds(1);
turbo::Duration diff;
while (state.KeepRunning()) {
Expand All @@ -76,12 +76,12 @@ BENCHMARK(BM_Time_Difference);
void BM_Time_ToDateTime_Turbo(benchmark::State& state) {
const turbo::TimeZone tz =
turbo::time_internal::LoadTimeZone("America/Los_Angeles");
turbo::Time t = turbo::FromUnixSeconds(1384569027);
turbo::Time t2 = turbo::FromUnixSeconds(1418962578);
turbo::Time t = turbo::Time::from_seconds(1384569027);
turbo::Time t2 = turbo::Time::from_seconds(1418962578);
while (state.KeepRunning()) {
std::swap(t, t2);
t += turbo::Seconds(1);
benchmark::DoNotOptimize(t.In(tz));
benchmark::DoNotOptimize(tz.At(t));
}
}
BENCHMARK(BM_Time_ToDateTime_Turbo);
Expand All @@ -105,10 +105,10 @@ BENCHMARK(BM_Time_ToDateTime_Libc);

void BM_Time_ToDateTimeUTC_Turbo(benchmark::State& state) {
const turbo::TimeZone tz = turbo::UTCTimeZone();
turbo::Time t = turbo::FromUnixSeconds(1384569027);
turbo::Time t = turbo::Time::from_seconds(1384569027);
while (state.KeepRunning()) {
t += turbo::Seconds(1);
benchmark::DoNotOptimize(t.In(tz));
benchmark::DoNotOptimize(tz.At(t));
}
}
BENCHMARK(BM_Time_ToDateTimeUTC_Turbo);
Expand All @@ -128,13 +128,13 @@ void BM_Time_ToDateTimeUTC_Libc(benchmark::State& state) {
BENCHMARK(BM_Time_ToDateTimeUTC_Libc);

//
// FromUnixMicros
// Time::from_microseconds
//

void BM_Time_FromUnixMicros(benchmark::State& state) {
int i = 0;
while (state.KeepRunning()) {
benchmark::DoNotOptimize(turbo::FromUnixMicros(i));
benchmark::DoNotOptimize(turbo::Time::from_microseconds(i));
++i;
}
}
Expand Down Expand Up @@ -285,15 +285,15 @@ BENCHMARK(BM_Time_FromCivilDay0_Libc);
//

void BM_Time_ToTimespec(benchmark::State& state) {
turbo::Time now = turbo::Now();
turbo::Time now = turbo::Time::current_time();
while (state.KeepRunning()) {
benchmark::DoNotOptimize(turbo::ToTimespec(now));
}
}
BENCHMARK(BM_Time_ToTimespec);

void BM_Time_FromTimespec(benchmark::State& state) {
timespec ts = turbo::ToTimespec(turbo::Now());
timespec ts = turbo::ToTimespec(turbo::Time::current_time());
while (state.KeepRunning()) {
if (++ts.tv_nsec == 1000 * 1000 * 1000) {
++ts.tv_sec;
Expand All @@ -310,16 +310,16 @@ BENCHMARK(BM_Time_FromTimespec);

void BM_Time_InfiniteFuture(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(turbo::InfiniteFuture());
benchmark::DoNotOptimize(turbo::Time::future_infinite());
}
}
BENCHMARK(BM_Time_InfiniteFuture);

void BM_Time_InfinitePast(benchmark::State& state) {
void BM_Time_past_infinite(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(turbo::InfinitePast());
benchmark::DoNotOptimize(turbo::Time::past_infinite());
}
}
BENCHMARK(BM_Time_InfinitePast);
BENCHMARK(BM_Time_past_infinite);

} // namespace
6 changes: 3 additions & 3 deletions carbin_cmake/carbin_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ option(CONDA_ENV_ENABLE "enable conda auto env" OFF)

option(CARBIN_USE_CXX11_ABI "use cxx11 abi or not" ON)

option(CARBIN_BUILD_TEST "enable project test or not" OFF)
option(CARBIN_BUILD_TEST "enable project test or not" ON)

option(CARBIN_BUILD_BENCHMARK "enable project benchmark or not" OFF)
option(CARBIN_BUILD_BENCHMARK "enable project benchmark or not" ON)

option(CARBIN_BUILD_EXAMPLES "enable project examples or not" OFF)
option(CARBIN_BUILD_EXAMPLES "enable project examples or not" ON)

option(CARBIN_DEPS_ENABLE " " ON)

Expand Down
2 changes: 1 addition & 1 deletion cmake/turbo_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (CARBIN_BUILD_TEST OR CARBIN_BUILD_BENCHMARK)
#include(require_gtest)
#include(require_gmock)
#include(require_doctest)
endif (CARBIN_BUILD_TEST)
endif (CARBIN_BUILD_TEST OR CARBIN_BUILD_BENCHMARK)

if (CARBIN_BUILD_BENCHMARK)
#include(require_benchmark)
Expand Down
28 changes: 22 additions & 6 deletions cmake/turbo_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ set(${PROJECT_NAME}_SKIP_BENCHMARK "")

list(APPEND ${PROJECT_NAME}_SKIP_TEST
"norun"
#[[ "base"
#[[ "base"
"container"
"algorithm"
"cleanup"
"crc"
"debugging"
"flags"
"functional"]]
)
list(APPEND ${PROJECT_NAME}_SKIP_BENCHMARK "norun"
"base"
"container"
"algorithm"
"cleanup"
"crc"
"debugging"
"flags"
"functional"]]
)
list(APPEND ${PROJECT_NAME}_SKIP_BENCHMARK "norun")
"functional"
"hash"
"log"
"numeric"
"profile"
"random"
"strings"
"synchronization"
"times"
"types"
)
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ carbin_cc_binary(
COPTS ${USER_CXX_FLAGS}
)
]]
add_subdirectory(log)
add_subdirectory(log)
add_subdirectory(times)
24 changes: 24 additions & 0 deletions examples/times/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (C) 2024 EA group inc.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

carbin_cc_binary(
NAME time_ex
SOURCES time_ex.cc
LINKS turbo::turbo
CXXOPTS ${CARBIN_CXX_OPTIONS}
)
35 changes: 35 additions & 0 deletions examples/times/time_ex.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright (C) 2024 EA group inc.
// Author: Jeff.li [email protected]
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
//
// Created by jeff on 24-5-30.
//
#include <turbo/times/time.h>
#include <iostream>

int main () {
turbo::Time t = turbo::Time::current_time();
std::cout << "current time is " << t << std::endl;
std::cout<< "current nano time is " << turbo::Time::current_nanoseconds() << std::endl;
std::cout<< "current micro time is " << turbo::Time::current_microseconds() << std::endl;
std::cout<< "current milli time is " << turbo::Time::current_milliseconds() << std::endl;
std::cout<< "current seconds time is " << turbo::Time::current_seconds() << std::endl;
std::cout<< "current double micro time is " << turbo::Time::current_microseconds<double>() << std::endl;
std::cout<< "current double milli time is " << turbo::Time::current_milliseconds<double>() << std::endl;
std::cout<< "current double seconds time is " << turbo::Time::current_seconds<double>() << std::endl;
return 0;
}
Loading

0 comments on commit 267bb12

Please sign in to comment.