diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/chrono/perf | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/chrono/perf')
-rw-r--r-- | src/boost/libs/chrono/perf/Jamfile.v2 | 147 | ||||
-rw-r--r-- | src/boost/libs/chrono/perf/store_now_in_vector.cpp | 153 |
2 files changed, 300 insertions, 0 deletions
diff --git a/src/boost/libs/chrono/perf/Jamfile.v2 b/src/boost/libs/chrono/perf/Jamfile.v2 new file mode 100644 index 00000000..8c68f74f --- /dev/null +++ b/src/boost/libs/chrono/perf/Jamfile.v2 @@ -0,0 +1,147 @@ +# Boost Chrono Library test Jamfile + +# Copyright Beman Dawes 2008 +# Copyright Vicente J. Botet Escriba 2009-2010 + +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt + +# See library home page at http://www.boost.org/libs/chrono + +import os ; +import feature ; + +project + : requirements + <target-os>freebsd:<linkflags>"-lrt" + <target-os>linux:<linkflags>"-lrt" + <toolset>pgi:<linkflags>"-lrt" + #<threading>single:<define>BOOST_CHRONO_THREAD_DISABLED + <toolset>msvc:<asynch-exceptions>on + <define>BOOST_CHRONO_USES_MPL_ASSERT + <toolset>sun:<define>BOOST_TYPEOF_EMULATION + <warnings>all + <toolset>gcc:<cxxflags>-Wextra + <toolset>gcc:<cxxflags>-pedantic + <toolset>gcc:<cxxflags>-Wno-long-long + <toolset>darwin:<cxxflags>-Wextra + <toolset>darwin:<cxxflags>-pedantic + <toolset>darwin:<cxxflags>-Wno-long-long + #<toolset>pathscale:<cxxflags>-Wextra + <toolset>pathscale:<cxxflags>-Wno-long-long + <toolset>pathscale:<cxxflags>-pedantic + <toolset>clang:<cxxflags>-Wextra + <toolset>clang:<cxxflags>-pedantic + <toolset>clang:<cxxflags>-Wno-long-long + <toolset>gcc-4.5.0,<target-os>windows:<cxxflags>-Wno-missing-field-initializers + <toolset>gcc-4.5.0,<target-os>windows:<cxxflags>-fdiagnostics-show-option + <toolset>msvc:<cxxflags>/wd4127 +# Note: Some of the remarks from the Intel compiler are disabled +# remark #304: access control not specified ("public" by default) +# remark #383: value copied to temporary, reference to temporary used +# remark #1418: external function definition with no prior declaration + <toolset>intel:<cxxflags>-wd304,383,1418 + <define>BOOST_CHRONO_VERSION=2 + ; + +rule chrono-run ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + : $(sources[1]:B)_shared ] + [ run $(sources) ../build//boost_chrono/<link>static + : : + : + : $(sources[1]:B)_static ] + [ run $(sources) + : : + : <define>BOOST_CHRONO_HEADER_ONLY + : $(sources[1]:B)_header ] + ; +} +rule chrono-run2 ( sources : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + : $(name)_shared ] + [ run $(sources) ../build//boost_chrono/<link>static + : : + : + : $(name)_static ] + [ run $(sources) + : : + : <define>BOOST_CHRONO_HEADER_ONLY + : $(name)_header ] + ; +} + + +rule chrono-run-mt ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + : $(sources[1]:B)_shared ] + [ run $(sources) ../build//boost_chrono/<link>static + : : + : + : $(sources[1]:B)_static ] + [ run $(sources) + : : + : <define>BOOST_CHRONO_HEADER_ONLY + : $(sources[1]:B)_header ] + ; +} +rule chrono-run2-mt ( sources : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + <library>/boost/system//boost_system + : $(name)_shared ] + [ run $(sources) ../build//boost_chrono/<link>static + : : + : + <library>/boost/system//boost_system + : $(name)_static ] + [ run $(sources) + : : + : <define>BOOST_CHRONO_HEADER_ONLY + : $(name)_header ] + ; +} +rule chrono-compile ( sources ) +{ + return + [ compile $(sources) + : + : $(sources[1]:B)_lib ] + [ compile $(sources) + : <define>BOOST_CHRONO_HEADER_ONLY + : $(sources[1]:B)_header ] + ; +} + +rule chrono-compile2 ( sources : name ) +{ + return + [ compile $(sources) + : + : $(name)_lib ] + [ compile $(sources) + : <define>BOOST_CHRONO_HEADER_ONLY + : $(name)_header ] + ; +} + + test-suite "perf" + : + [ chrono-run store_now_in_vector.cpp ] + ; + diff --git a/src/boost/libs/chrono/perf/store_now_in_vector.cpp b/src/boost/libs/chrono/perf/store_now_in_vector.cpp new file mode 100644 index 00000000..6c5c4bba --- /dev/null +++ b/src/boost/libs/chrono/perf/store_now_in_vector.cpp @@ -0,0 +1,153 @@ +// Copyright 2011 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/chrono.hpp> +#include <boost/chrono/chrono_io.hpp> +#include <libs/chrono/example/timer.hpp> +#include <boost/chrono/process_cpu_clocks.hpp> +#include <vector> + +//#define BOOST_CHRONO_HAS_TIMES_AND_CLOCK + +#ifdef BOOST_CHRONO_HAS_TIMES_AND_CLOCK +#include <sys/time.h> //for gettimeofday and timeval +#include <sys/times.h> //for times +#include <unistd.h> +#endif + + +static const std::size_t size = 1000000; + +typedef boost::chrono::timer<boost::chrono::high_resolution_clock> Stopwatch; + +template <typename Clock> +void perf_constant(std::vector<typename Clock::time_point>& vec) +{ + for (int i=size-1; i>=0; --i) + { + vec[i]=typename Clock::time_point(); + } +} + +template <typename Clock> +void perf(std::vector<typename Clock::time_point>& vec) +{ + for (int i=size-1; i>=0; --i) + { + vec[i]=Clock::now(); + } +} + +template <typename Clock> +void test() +{ + std::vector<typename Clock::time_point> vec(size); + Stopwatch sw1; + perf_constant<Clock>(vec); + Stopwatch::duration t1 = sw1.elapsed(); + Stopwatch sw2; + perf<Clock>(vec); + Stopwatch::duration t2 = sw2.elapsed(); + std::cout <<" "<< (t2-t1) << std::endl; + //std::cout <<" "<< ((t2-t1)/size) << std::endl; + std::size_t cnt=0; + for (int i=size-1; i>0; --i) + { + if (vec[i]!=vec[i-1]) ++cnt; + } + std::cout <<"changes: "<< cnt << std::endl; + +} + + + + + +#ifdef BOOST_CHRONO_HAS_TIMES_AND_CLOCK +void perf2(std::vector<clock_t>& vec) +{ + Stopwatch sw; + for (int i=size-1; i>=0; --i) + { + tms tm; + vec[i]=::times(&tm); + } + std::cout << sw.elapsed() << std::endl; +} + +void perf3(std::vector<clock_t>& vec) +{ + Stopwatch sw; + for (int i=size-1; i>=0; --i) + { + vec[i]=::clock(); + } + std::cout << sw.elapsed() << std::endl; +} + +void test2() +{ + std::vector<clock_t> vec(size); + perf2(vec); + std::size_t cnt=0; + for (int i=10; i>0; --i) + { + if (vec[i]!=vec[i-1]) ++cnt; + std::cout << vec[i] << " " ; + } + std::cout<< std::endl; + std::cout <<"changes: "<< cnt << std::endl; +} + +void test3() +{ + std::vector<clock_t> vec(size); + perf3(vec); + std::size_t cnt=0; + for (int i=10; i>0; --i) + { + if (vec[i]!=vec[i-1]) ++cnt; + std::cout << vec[i] << " " ; + } + std::cout<< std::endl; + std::cout <<"changes: "<< cnt << std::endl; +} + +#endif + +int main() { + + std::cout << "system_clock "; + test<boost::chrono::system_clock>(); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << "steady_clock " ; + test<boost::chrono::steady_clock>(); +#endif + std::cout << "high_resolution_clock " ; + test<boost::chrono::high_resolution_clock>(); + +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + std::cout << "process_real_cpu_clock "; + test<boost::chrono::process_real_cpu_clock>(); +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP + std::cout << "process_user_cpu_clock "; + test<boost::chrono::process_user_cpu_clock>(); + std::cout << "process_system_cpu_clock " ; + test<boost::chrono::process_system_cpu_clock>(); + std::cout << "process_cpu_clock " ; + test<boost::chrono::process_cpu_clock>(); +#endif +#endif + std::cout << "system_clock "; + test<boost::chrono::system_clock>(); +#if 0 + std::cout << "times "; + test2(); + std::cout << "clock "; + test3(); +#endif + return 1; +} |