1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-11-05 09:29:01 -06:00

Initial commit

This commit is contained in:
Crimson-Hawk
2024-03-05 16:42:40 +08:00
commit f1e4595ebf
39576 changed files with 7006612 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
* text=auto !eol svneol=native#text/plain
*.gitattributes text svneol=native#text/plain
# Scriptish formats
*.bat text svneol=native#text/plain
*.bsh text svneol=native#text/x-beanshell
*.cgi text svneol=native#text/plain
*.cmd text svneol=native#text/plain
*.js text svneol=native#text/javascript
*.php text svneol=native#text/x-php
*.pl text svneol=native#text/x-perl
*.pm text svneol=native#text/x-perl
*.py text svneol=native#text/x-python
*.sh eol=lf svneol=LF#text/x-sh
configure eol=lf svneol=LF#text/x-sh
# Image formats
*.bmp binary svneol=unset#image/bmp
*.gif binary svneol=unset#image/gif
*.ico binary svneol=unset#image/ico
*.jpeg binary svneol=unset#image/jpeg
*.jpg binary svneol=unset#image/jpeg
*.png binary svneol=unset#image/png
*.tif binary svneol=unset#image/tiff
*.tiff binary svneol=unset#image/tiff
*.svg text svneol=native#image/svg%2Bxml
# Data formats
*.pdf binary svneol=unset#application/pdf
*.avi binary svneol=unset#video/avi
*.doc binary svneol=unset#application/msword
*.dsp text svneol=crlf#text/plain
*.dsw text svneol=crlf#text/plain
*.eps binary svneol=unset#application/postscript
*.gz binary svneol=unset#application/gzip
*.mov binary svneol=unset#video/quicktime
*.mp3 binary svneol=unset#audio/mpeg
*.ppt binary svneol=unset#application/vnd.ms-powerpoint
*.ps binary svneol=unset#application/postscript
*.psd binary svneol=unset#application/photoshop
*.rdf binary svneol=unset#text/rdf
*.rss text svneol=unset#text/xml
*.rtf binary svneol=unset#text/rtf
*.sln text svneol=native#text/plain
*.swf binary svneol=unset#application/x-shockwave-flash
*.tgz binary svneol=unset#application/gzip
*.vcproj text svneol=native#text/xml
*.vcxproj text svneol=native#text/xml
*.vsprops text svneol=native#text/xml
*.wav binary svneol=unset#audio/wav
*.xls binary svneol=unset#application/vnd.ms-excel
*.zip binary svneol=unset#application/zip
# Text formats
.htaccess text svneol=native#text/plain
*.bbk text svneol=native#text/xml
*.cmake text svneol=native#text/plain
*.css text svneol=native#text/css
*.dtd text svneol=native#text/xml
*.htm text svneol=native#text/html
*.html text svneol=native#text/html
*.ini text svneol=native#text/plain
*.log text svneol=native#text/plain
*.mak text svneol=native#text/plain
*.qbk text svneol=native#text/plain
*.rst text svneol=native#text/plain
*.sql text svneol=native#text/x-sql
*.txt text svneol=native#text/plain
*.xhtml text svneol=native#text/xhtml%2Bxml
*.xml text svneol=native#text/xml
*.xsd text svneol=native#text/xml
*.xsl text svneol=native#text/xml
*.xslt text svneol=native#text/xml
*.xul text svneol=native#text/xul
*.yml text svneol=native#text/plain
boost-no-inspect text svneol=native#text/plain
CHANGES text svneol=native#text/plain
COPYING text svneol=native#text/plain
INSTALL text svneol=native#text/plain
Jamfile text svneol=native#text/plain
Jamroot text svneol=native#text/plain
Jamfile.v2 text svneol=native#text/plain
Jamrules text svneol=native#text/plain
Makefile* text svneol=native#text/plain
README text svneol=native#text/plain
TODO text svneol=native#text/plain
# Code formats
*.c text svneol=native#text/plain
*.cpp text svneol=native#text/plain
*.h text svneol=native#text/plain
*.hpp text svneol=native#text/plain
*.ipp text svneol=native#text/plain
*.tpp text svneol=native#text/plain
*.jam text svneol=native#text/plain
*.java text svneol=native#text/plain

View File

@@ -0,0 +1,387 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-10
- toolset: gcc-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
install: clang-7
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-10
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-11
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-12
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.1
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2016
- toolset: msvc-14.2
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- name: Run tests
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
posix-cmake-subdir:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
shared: OFF
- os: ubuntu-18.04
shared: ON
- os: ubuntu-20.04
shared: OFF
- os: ubuntu-20.04
shared: ON
- os: macos-10.15
shared: OFF
- os: macos-10.15
shared: ON
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Use library with add_subdirectory
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
cmake --build .
ctest --output-on-failure --no-tests=error
posix-cmake-install:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
shared: OFF
- os: ubuntu-18.04
shared: ON
- os: ubuntu-20.04
shared: OFF
- os: ubuntu-20.04
shared: ON
- os: macos-10.15
shared: OFF
- os: macos-10.15
shared: ON
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
- name: Build
run: |
cd ../boost-root/__build__
cmake --build .
- name: Install
run: |
cd ../boost-root/__build__
cmake --build . --target install
- name: Use the installed library
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
cmake --build .
export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH
ctest --output-on-failure --no-tests=error
posix-cmake-test:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
shared: OFF
- os: ubuntu-18.04
shared: ON
- os: ubuntu-20.04
shared: OFF
- os: ubuntu-20.04
shared: ON
- os: macos-10.15
shared: OFF
- os: macos-10.15
shared: ON
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
- name: Build tests
run: |
cd ../boost-root/__build__
cmake --build . --target tests
- name: Run tests
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error

View File

@@ -0,0 +1,184 @@
# Copyright 2016-2018 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
language: cpp
sudo: false
branches:
only:
- master
- develop
- /feature\/.*/
env:
matrix:
- BOGUS_JOB=true
matrix:
exclude:
- env: BOGUS_JOB=true
include:
- os: linux
compiler: g++
env: TOOLSET=gcc CXXSTD=03,11
- os: linux
compiler: g++-4.4
env: TOOLSET=gcc CXXSTD=98,0x
addons:
apt:
packages:
- g++-4.4
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.6
env: TOOLSET=gcc CXXSTD=03,0x
addons:
apt:
packages:
- g++-4.6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.8
env: TOOLSET=gcc CXXSTD=03,11
addons:
apt:
packages:
- g++-4.8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-5
env: TOOLSET=gcc CXXSTD=03,11,14,1z
addons:
apt:
packages:
- g++-5
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-6
env: TOOLSET=gcc CXXSTD=03,11,14,1z
addons:
apt:
packages:
- g++-6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-7
env: TOOLSET=gcc CXXSTD=03,11,14,17
addons:
apt:
packages:
- g++-7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-8
env: TOOLSET=gcc CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- g++-8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-9
env: TOOLSET=gcc CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- g++-9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-9
env: UBSAN=1 TOOLSET=gcc CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
addons:
apt:
packages:
- g++-9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++
env: TOOLSET=clang CXXSTD=03,11,14,1z
- os: linux
compiler: clang++
env: UBSAN=1 TOOLSET=clang CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1
- os: linux
dist: trusty
compiler: clang++-libc++
env: TOOLSET=clang CXXSTD=03,11,14,1z
addons:
apt:
packages:
- libc++-dev
- os: linux
dist: trusty
compiler: clang++-libc++
env: UBSAN=1 TOOLSET=clang CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1
addons:
apt:
packages:
- libc++-dev
- os: osx
compiler: clang++
env: TOOLSET=clang CXXSTD=03,11,14,1z
- os: linux
env: CMAKE=1
script:
- mkdir __build__ && cd __build__
- cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer ..
- cmake --build . --target tests
- ctest --output-on-failure --no-tests=error
- os: linux
env: CMAKE=1 BUILD_SHARED_LIBS=ON
script:
- mkdir __build__ && cd __build__
- cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer -DBUILD_SHARED_LIBS=ON ..
- cmake --build . --target tests
- ctest --output-on-failure --no-tests=error
install:
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
- cd ..
- git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/boostdep
- git submodule update --init tools/cmake
- cp -r $TRAVIS_BUILD_DIR/* libs/timer
- python tools/boostdep/depinst/depinst.py timer
- ./bootstrap.sh
- ./b2 headers
script:
- |-
echo "using $TOOLSET : : $TRAVIS_COMPILER ;" > ~/user-config.jam
- ./b2 -j3 -l120 --verbose-test libs/timer/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${UBSAN:+cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined linkflags=-fsanitize=undefined debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}
notifications:
email:
on_success: always

View File

@@ -0,0 +1,45 @@
# Copyright 2018, 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_timer VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_timer
src/auto_timers_construction.cpp
src/cpu_timer.cpp
)
add_library(Boost::timer ALIAS boost_timer)
target_include_directories(boost_timer PUBLIC include)
target_compile_definitions(boost_timer
PUBLIC
BOOST_TIMER_NO_LIB
)
if(BUILD_SHARED_LIBS)
target_compile_definitions(boost_timer PUBLIC BOOST_TIMER_DYN_LINK)
else()
target_compile_definitions(boost_timer PUBLIC BOOST_TIMER_STATIC_LINK)
endif()
target_link_libraries(boost_timer
PUBLIC
Boost::config
Boost::core
Boost::system
PRIVATE
Boost::chrono
Boost::io
Boost::predef
Boost::throw_exception
)
if(BUILD_TESTING)
add_subdirectory(test)
endif()

View File

@@ -0,0 +1,180 @@
constant BOOST_VERSION : 1.79.0 ;
constant BOOST_VERSION_ABI_TAG : 1_79 ;
constant BOOST_JAMROOT_MODULE : $(__name__) ;
import boostcpp ;
import feature ;
boostcpp.set-version $(BOOST_VERSION) ;
project boost : requirements
<include>include&&"D:/a/1/s/build/vcpkg_installed/x64-windows/include"
<define>BOOST_ALL_NO_LIB=1
<tag>@$(__name__).tag
;
rule boost-install ( libraries * )
{
stagedir = [ option.get stagedir ] ;
install stage
: $(libraries)
: <location>$(stagedir)/lib ;
}
rule tag ( name : type ? : property-set )
{
return [ boostcpp.tag $(name) : $(type) : $(property-set) ] ;
}
rule python-tag ( name : type ? : property-set )
{
return [ boostcpp.python-tag $(name) : $(type) : $(property-set) ] ;
}
if "boost-timer" != "boost-system"
{
use-project /boost/system : . ;
lib boost_system : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_system-vc140-mt.lib" <variant>release ;
lib boost_system : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_system-vc140-mt-gd.lib" <variant>debug ;
explicit boost_system ;
use-project /boost : . ;
alias system : boost_system ;
}
if "boost-timer" != "boost-chrono"
{
use-project /boost/chrono : . ;
lib boost_chrono : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_chrono-vc140-mt.lib" <variant>release ;
lib boost_chrono : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_chrono-vc140-mt-gd.lib" <variant>debug ;
explicit boost_chrono ;
}
if "boost-timer" != "boost-regex"
{
use-project /boost/regex : . ;
lib boost_regex : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_regex-vc140-mt.lib" <variant>release ;
lib boost_regex : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_regex-vc140-mt-gd.lib" <variant>debug ;
explicit boost_regex ;
}
if "boost-timer" != "boost-date-time"
{
use-project /boost/date_time : . ;
lib boost_date_time : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_date_time-vc140-mt.lib" <variant>release -<library>/boost/date_time//boost_date_time ;
lib boost_date_time : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_date_time-vc140-mt-gd.lib" <variant>debug -<library>/boost/date_time//boost_date_time ;
explicit boost_date_time ;
}
if "boost-timer" != "boost-thread"
{
use-project /boost/thread : . ;
lib boost_thread : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_thread-vc140-mt.lib" <variant>release : : <library>/boost/date_time//boost_date_time ;
lib boost_thread : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_thread-vc140-mt-gd.lib" <variant>debug : : <library>/boost/date_time//boost_date_time ;
explicit boost_thread ;
}
if "boost-timer" != "boost-timer"
{
use-project /boost/timer : . ;
lib boost_timer : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_timer-vc140-mt.lib" <variant>release ;
lib boost_timer : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_timer-vc140-mt-gd.lib" <variant>debug ;
explicit boost_timer ;
}
if "boost-timer" != "boost-filesystem"
{
use-project /boost/filesystem : . ;
lib boost_filesystem : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_filesystem-vc140-mt.lib" <variant>release : : <library>/boost/system//boost_system ;
lib boost_filesystem : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_filesystem-vc140-mt-gd.lib" <variant>debug : : <library>/boost/system//boost_system ;
explicit boost_filesystem ;
}
if "boost-timer" != "boost-atomic"
{
use-project /boost/atomic : . ;
lib boost_atomic : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_atomic-vc140-mt.lib" <variant>release ;
lib boost_atomic : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_atomic-vc140-mt-gd.lib" <variant>debug ;
explicit boost_atomic ;
}
if "boost-timer" != "boost-context"
{
feature.feature segmented-stacks : on : optional propagated composite ;
feature.compose <segmented-stacks>on : <define>BOOST_USE_SEGMENTED_STACKS ;
use-project /boost/context : . ;
lib boost_context : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_context-vc140-mt.lib" <variant>release ;
lib boost_context : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_context-vc140-mt-gd.lib" <variant>debug ;
explicit boost_context ;
}
if "boost-timer" != "boost-test"
{
use-project /boost/test : . ;
lib boost_unit_test_framework : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_unit_test_framework-vc140-mt.lib" <variant>release ;
lib boost_unit_test_framework : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_unit_test_framework-vc140-mt-gd.lib" <variant>debug ;
explicit boost_unit_test_framework ;
}
if "boost-timer" != "boost-serialization"
{
use-project /boost/serialization : . ;
lib boost_serialization : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_serialization-vc140-mt.lib" <variant>release ;
lib boost_serialization : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_serialization-vc140-mt-gd.lib" <variant>debug ;
explicit boost_serialization ;
}
if "boost-timer" != "boost-mpi"
{
use-project /boost/mpi : . ;
lib boost_mpi : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_mpi-vc140-mt.lib" <variant>release : : <library>/boost/serialization//boost_serialization ;
lib boost_mpi : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_mpi-vc140-mt-gd.lib" <variant>debug : : <library>/boost/serialization//boost_serialization ;
explicit boost_mpi ;
}
if "boost-timer" != "boost-container"
{
use-project /boost/container : . ;
lib boost_container : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_container-vc140-mt.lib" <variant>release ;
lib boost_container : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_container-vc140-mt-gd.lib" <variant>debug ;
explicit boost_container ;
}
if "boost-timer" != "boost-python"
{
use-project /boost/python : . ;
lib boost_python : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/lib/boost_python-vc140-mt.lib" <variant>release ;
lib boost_python : : <file>"D:/a/1/s/build/vcpkg_installed/x64-windows/debug/lib/boost_python-vc140-mt-gd.lib" <variant>debug ;
explicit boost_python ;
}
rule requires ( foo * )
{
}
rule boost-lib ( name : sources * : requirements * : default-build * : usage-requirements * )
{
name = boost_$(name) ;
lib $(name) : $(sources) : $(requirements) : $(default-build) : $(usage-requirements) ;
boost-install $(name) ;
}
use-project /boost/boost-timer : build ;
build-project build ;

View File

@@ -0,0 +1,93 @@
# Copyright 2016-2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
version: 1.0.{build}-{branch}
shallow_clone: true
branches:
only:
- master
- develop
- /feature\/.*/
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0
ADDRMD: 32
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-12.0,msvc-14.0
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
CXXSTD: 14,17
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: clang-win
CXXSTD: 14,17
ADDRMD: 64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: msvc-14.2
CXXSTD: 14,17
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE: 1
install:
- set BOOST_BRANCH=develop
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
- cd ..
- git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/boostdep
- git submodule update --init tools/cmake
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\timer\
- python tools/boostdep/depinst/depinst.py timer
- cmd /c bootstrap
- b2 -d0 headers
build: off
test_script:
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
- if "%CMAKE%" == "" b2 -j3 -l120 --verbose-test libs/timer/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release
- if not "%CMAKE%" == "" mkdir __build_static && cd __build_static
- if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer ..
- if not "%CMAKE%" == "" cmake --build . --target tests --config Debug && ctest --output-on-failure -C Debug
- if not "%CMAKE%" == "" cmake --build . --target tests --config Release && ctest --output-on-failure -C Release
- if not "%CMAKE%" == "" cmake --build . --target tests --config MinSizeRel && ctest --output-on-failure -C MinSizeRel
- if not "%CMAKE%" == "" cmake --build . --target tests --config RelWithDebInfo && ctest --output-on-failure -C RelWithDebInfo
- if not "%CMAKE%" == "" cd ..
- if not "%CMAKE%" == "" mkdir __build_shared && cd __build_shared
- if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer -DBUILD_SHARED_LIBS=ON ..
- if not "%CMAKE%" == "" cmake --build . --target tests --config Debug && ctest --output-on-failure -C Debug
- if not "%CMAKE%" == "" cmake --build . --target tests --config Release && ctest --output-on-failure -C Release
- if not "%CMAKE%" == "" cmake --build . --target tests --config MinSizeRel && ctest --output-on-failure -C MinSizeRel
- if not "%CMAKE%" == "" cmake --build . --target tests --config RelWithDebInfo && ctest --output-on-failure -C RelWithDebInfo

View File

@@ -0,0 +1,27 @@
# Boost Timer Library Build Jamfile
# (C) Copyright Beman Dawes 2002, 2006, 2011
# Distributed under the Boost Software License, Version 1.0.
# See www.boost.org/LICENSE_1_0.txt
# See library home page at http://www.boost.org/libs/timer
project boost/timer
: source-location ../src
: requirements
<library>/boost/chrono//boost_chrono
: usage-requirements # pass these requirement to dependants (i.e. users)
<link>shared:<define>BOOST_TIMER_DYN_LINK=1
<link>static:<define>BOOST_TIMER_STATIC_LINK=1
;
SOURCES = auto_timers_construction cpu_timer ;
lib boost_timer
: $(SOURCES).cpp
: <link>shared:<define>BOOST_TIMER_DYN_LINK=1
<link>static:<define>BOOST_TIMER_STATIC_LINK=1
;
boost-install boost_timer ;

View File

@@ -0,0 +1,693 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>CPU Timers</title>
<style type="text/css">
ins {background-color:#A0FFA0}
del {background-color:#FFA0A0}
body
{
font-family: sans-serif;
max-width : 8.5in;
margin: 1em;
}
</style>
</head>
<body>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="750">
<tr>
<td width="300">
<a href="../../../index.htm">
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="300" height="86" border="0"></a></td>
<td align="middle" width="430">
<font size="7">Timer Library<br>
CPU Timers</font></td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
<tr>
<td><a href="index.html">Timer Home</a> &nbsp;&nbsp;
<a href="cpu_timers.html">CPU timers</a> &nbsp;&nbsp;
<a href="original_timer.html">Original timers</a> &nbsp;&nbsp;
</td>
</tr>
</table>
<h2><a name="Introduction">Introduction</a></h2>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" align="right">
<tr>
<td width="100%" bgcolor="#D7EEFF" align="center">
<i><b>Contents</b></i></td>
</tr>
<tr>
<td width="100%" bgcolor="#E8F5FF">
<a href="#Introduction">Introduction</a><br>
<a href="#Example">Using the timers</a><br>
&nbsp; <a href="#using-auto_cpu_timer">Using <code>auto_cpu_timer</code></a><br>
&nbsp; <a href="#using-cpu_timer">Using <code>cpu_timer</code></a><br>
<a href="#Timer-accuracy">Timer accuracy</a><br>
&nbsp; <a href="#Resolution">Resolution</a><br>
&nbsp; <a href="#Other-concerns">Other concerns</a><br>
&nbsp; <a href="#Recommendations">Recommendations</a><br>
<a href="#Reference">Reference</a><br>
<code>&nbsp;<a href="#Synopsis">&lt;boost/timer/timer.hpp&gt;</a></code><a href="#Synopsis">
synopsis</a><br>
&nbsp; <a href="#Default-format">Default format</a><br>
&nbsp; <a href="#nanosecond_type">Typedef <code>nanosecond_type</code></a><br>
&nbsp; <a href="#Namespace-scope-functions">Namespace scope functions</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#format"><code>format()</code></a><br>
&nbsp;
<a href="#Class-cpu_timer">Class <code>cpu_timer</code></a><br>
&nbsp;&nbsp;<code>&nbsp; <a href="#cpu_timer-constructors">cpu_timer</a></code><a href="#cpu_timer-constructors">
constructors, destructor</a><br>
&nbsp;&nbsp;&nbsp; &nbsp;<code><a href="#cpu_timer-observers">cpu_timer</a></code><a href="#cpu_timer-observers">
observers</a><br>
&nbsp;&nbsp;<code>&nbsp; <a href="#cpu_timer-actions">cpu_timer</a></code><a href="#cpu_timer-actions">
actions</a><br>
&nbsp; <a href="#Class-auto_cpu_timer">Class <code>auto_cpu_timer</code></a><br>
&nbsp;&nbsp;&nbsp;<code> <a href="#auto_cpu_timer-constructors">auto_cpu_timer</a></code><a href="#auto_cpu_timer-constructors"> constructors</a><br>
&nbsp;&nbsp;&nbsp;<code> <a href="#auto_cpu_timer-destructor">auto_cpu_timer</a></code><a href="#auto_cpu_timer-destructor"> destructor</a><br>
&nbsp;&nbsp;&nbsp;&nbsp; <a href="#auto_cpu_timer-observers"><code>
auto_cpu_timer</code> observers</a><br>
&nbsp;&nbsp;&nbsp;<code> <a href="#auto_cpu_timer-actions">auto_cpu_timer</a></code><a href="#auto_cpu_timer-actions"> actions</a><br>
<a href="#History">History</a><br>
<a href="#Acknowledgements">Acknowledgements</a></tr>
</table>
<p>Knowing how long a program takes to execute is useful in both test and
production environments. It may also be helpful if such timing information is broken down
into wall clock time, CPU time spent by the user, and CPU time spent by the
operating system servicing user requests.</p>
<p>Class <code><a href="#Class-cpu_timer">cpu_timer</a></code> measures
wall clock time, user CPU process time, and system CPU process time. Class <code>
<a href="#Class-auto_cpu_timer">auto_cpu_timer</a></code> is a refinement of
<code>cpu_timer</code> that automatically reports the elapsed times when an <code>
auto_cpu_timer</code> object is destroyed.</p>
<h2><a name="Setup">Setup</a></h2>
<p>Boost.Timer is implemented as a separately compiled library, so you must
install binaries in a location that can be found by your linker. If you followed
the
<a href="http://www.boost.org/doc/libs/release/more/getting_started/index.html">
Boost Getting Started</a> instructions, that's already done for you.</p>
<h2><a name="Example">Using the timers</a></h2>
<h3>Using <code><a name="using-auto_cpu_timer">auto_cpu_timer</a></code></h3>
<p>The simplest and most common use is to add the two lines highlighted below
to a scope you want to time. See <code>
<a href="../example/auto_cpu_timer_example.cpp">auto_cpu_timer_example.cpp</a></code>
for the source code. </p>
<blockquote>
<pre><span style="background-color: #D7EEFF">#include &lt;boost/timer/</span><span style="background-color: #D7EEFF">timer.hpp</span><span style="background-color: #D7EEFF">&gt;</span>
#include &lt;cmath&gt;
int main()
{
<span style="background-color: #D7EEFF">boost::timer::auto_cpu_timer</span><span style="background-color: #D7EEFF"> t;</span>
for (long i = 0; i &lt; 100000000; ++i)
std::sqrt(123.456L); // burn some time
return 0;
}</pre>
</blockquote>
<p>When the <code>auto_cpu_timer</code> object is created, it starts timing. When
it is destroyed at the end of the scope, its destructor stops the timer and
displays timing information on the default output stream, <code>std::cout</code>.</p>
<p>The output of this program will look something like this:</p>
<p><code>&nbsp;&nbsp;&nbsp; 5.713010s wall, 5.709637s user + 0.000000s system =
5.709637s CPU (99.9%)</code></p>
<p>In other words, this program ran in <code>5.713010</code> seconds as would be measured by a
clock on the wall, the operating system charged it for <code>5.709637</code> seconds of user CPU
time and 0 seconds of system CPU time, the total of these two was <code>5.709637</code>, and that
represented <code>99.9</code> percent of the wall clock time.</p>
<p>The output stream, number of decimal places reported, and reporting format
can be controlled by <code>auto_cpu_timer</code> constructor arguments. Here is
what the output from the above program would look like for several different
sets of constructor arguments:</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td><i><b>Construction</b></i></td>
<td><i><b>Output</b></i></td>
</tr>
<tr>
<td><code><font size="1">t</font></code></td>
<td><code><font size="1">5.713010s wall, 5.709637s user + 0.000000s system = 5.709637s
CPU (99.9%)</font></code></td>
</tr>
<tr>
<td><code><font size="1">t(std::cerr</font><font size="1">, 2)</font></code></td>
<td><code><font size="1">5.71s wall, 5.70s user + 0.00s system = 5.70s CPU (99.9%)</font></code></td>
</tr>
<tr>
<td><code><font size="1">t(1)</font></code></td>
<td><code><font size="1">5.7s wall, 5.7s user + 0.0s system = 5.7s CPU (99.9%)</font></code></td>
</tr>
<tr>
<td><code><font size="1">t(3, &quot;%w seconds\n&quot;)</font></code></td>
<td><code><font size="1">5.713 seconds<br>
&nbsp;</font></code></td>
</tr>
<tr>
<td><code><font size="1">t(&quot;%t</font><font size="1"> sec CPU, %w sec real&quot;)
</font> </code></td>
<td><code><font size="1">5.709637 sec CPU, 5.713010 sec real</font></code></td>
</tr>
</table>
<p> The processing of the format string is described <a href="#format">here</a>.</p>
<h3> Using <code><a name="using-cpu_timer">cpu_timer</a></code></h3>
<p> The following code creates a checkpoint every 20 CPU seconds:</p>
<blockquote>
<pre>using boost::timer::cpu_timer;
using boost::timer::cpu_times;
using boost::timer::nanosecond_type;
...
nanosecond_type const twenty_seconds(20 * 1000000000LL);
nanosecond_type last(0);
cpu_timer timer;
while (more_transactions)
{
process_a_transaction();
cpu_times const elapsed_times(timer.elapsed());
nanosecond_type const elapsed(elapsed_times.system
+ elapsed_times.user);
if (elapsed &gt;= twenty_seconds)
{
... create a checkpoint ...
last = elapsed;
}
}</pre>
</blockquote>
<h2><a name="Timer-accuracy">Timer accuracy</a></h2>
<p>How accurate are these timers? </p>
<h3><a name="Resolution">Resolution</a></h3>
<p dir="ltr">The resolution of a clock, and thus timers built on that clock,
is the minimum period time that can be measured. The program <code>
<a href="../test/cpu_timer_info.cpp">cpu_timer_info.cpp</a></code> measures
the resolution of <code>cpu_timer</code>.</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td rowspan="2" bgcolor="#D7EEFF">O/S</td>
<td rowspan="2" bgcolor="#D7EEFF">Processor</td>
<td colspan="2" align="center" bgcolor="#D7EEFF">Wall-clock</td>
<td colspan="2" align="center" bgcolor="#D7EEFF">CPU</td>
</tr>
<tr>
<td bgcolor="#D7EEFF">Resolution</td>
<td bgcolor="#D7EEFF">Comments</td>
<td align="center" bgcolor="#D7EEFF">User<br>
Resolution</td>
<td align="center" bgcolor="#D7EEFF">System<br>
Resolution</td>
</tr>
<tr>
<td>Mac OS X Lion</td>
<td>Intel circa 2007</td>
<td align="right">2100ns<br>
2200ns</td>
<td>Some variation within a range.</td>
<td>10000000ns</td>
<td>10000000ns</td>
</tr>
<tr>
<td>Ubuntu Linux 11.4</td>
<td>Intel circa 2005</td>
<td align="right">516ns</td>
<td>Very little variation, typically less than 5ns </td>
<td>10000000ns</td>
<td>10000000ns</td>
</tr>
<tr>
<td>Windows 7</td>
<td>Intel Core i7 860 @ 2.9 GHz</td>
<td align="right">366ns</td>
<td>Some variation, usually in multiples of 366ns</td>
<td>15600100ns</td>
<td>15600100ns</td>
</tr>
<tr>
<td>Windows 7</td>
<td>Intel Mobile T7200 @ 2.0 GHz</td>
<td align="right">2050ns</td>
<td>Much variation. Resolution degrades when processor slows, probably due
to known chipset errata. </td>
<td>15600100ns</td>
<td>15600100ns</td>
</tr>
<tr>
<td>Windows XP</td>
<td>Intel Atom N2800 @ 1.0 GHz</td>
<td align="right">1437ns</td>
<td>Some variation.</td>
<td>15625000ns</td>
<td>15625000ns</td>
</tr>
</table>
<h3><a name="Other-concerns">Other concerns</a></h3>
<p>Wall-clock timings are subject to many outside influences, such as the impact
of other processes.</p>
<blockquote>
<p><code>cpu_timer</code> and <code>auto_cpu_timer</code> obtain Wall-clock
timings from Boost.Chrono's <code>high_resolution_clock</code>. On Intel
compatible CPU's running Windows, Linux, and Mac OS X, this is a &quot;steady
clock&quot; [C++11 20.11.3], but may not be steady on other platforms. <code>
<a href="../test/cpu_timer_info.cpp">cpu_timer_info.cpp</a></code> reports
whether or not the <code>high_resolution_clock</code> is steady on a
particular platform.</p>
<p><i><b><a name="Steady-clocks">Steady clocks</a></b></i> are defined by the
C++11 standard as clocks for which values never decrease as physical time
advances and for which values advance at a steady rate relative to real time.
That is, the clock may not be adjusted. Clocks that are steady never run
backwards, even when the operating system's clock is reset backwards such as
during a daylight saving time transition.</p>
</blockquote>
<p>Timings of debug builds are often several times slower
than release builds, because compiler optimization is turned off and
because libraries often supply very expensive error checks on debug builds.</p>
<p>Synthetic benchmark code may be optimized way, particularly if NDEBUG is
defined. It may be
necessary to inspect generated code to verify this isn't happening.</p>
<h3 dir="ltr"><a name="Recommendations">Recommendations</a></h3>
<p dir="ltr">Think about what is important to your application. For a
production process, the wall clock time may be what is most important. To
study the efficiency of code, total CPU time (user + system) is often a much better measure.</p>
<p dir="ltr">A useful recommendation is to never trust timings unless they are
(1) at least 100 times longer than the CPU time resolution, (2) run multiple
times, and (3) run on release builds. And results that are too good to be true
need to be should be investigated skeptically.</p>
<p>Shared libraries (DLLs and .so's) may incur extra time delays, including expensive
disk accesses, the first time a timer or other function is called. If that
would be misleading, static linking should be considered.</p>
<h2> <a name="Reference">Reference</a></h2>
<p> Specifications are given in the style of the C++ standard library (C++11,
17.5.1.4 [structure.specifications]). An additional <i>Overview</i> element may
be provided to aid understanding. <i>Overview</i> elements are only informative
- actual semantics are given by the other detailed specification elements.</p>
<p dir="ltr"> Functions not specified as <code>noexcept</code> will throw <code>
std::bad_alloc</code> exceptions if a memory allocation error occurs. Other
errors are reported by time values of -1. [<i>Note:</i> Modern hardware and
operating systems have robust clock subsystems, so such errors are unusual if
even possible at all. <i>-- end note</i>]</p>
<p dir="ltr"> The Timer library meets the same data race avoidance requirements
as the C++11 standard library (17.6.5.9 [res.on.data.races]). Shared objects of
Timer library types risk undefined behavior unless the user supplies a locking
mechanism. See C++11, 17.6.4.10 [res.on.objects], <i>Shared objects and the
library</i>. </p>
<h3>
<code>&lt;boost/timer/timer.hpp&gt;</code> <a name="Synopsis">synopsis</a></h3>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td bgcolor="#D7EEFF">
<blockquote>
<pre>namespace boost
{
namespace timer
{
class <a href="#Class-cpu_timer">cpu_timer</a>; // wall clock, user, and system timer
class <a href="#Class-auto_cpu_timer">auto_cpu_timer</a>; // automatic report() on destruction
typedef boost::int_least64_t nanosecond_type;
struct cpu_times
{
nanosecond_type wall;
nanosecond_type user;
nanosecond_type system;
void clear();
};
const int <a name="default_places">default_places</a> = 6;
std::string format(const cpu_times&amp; times, short places, const std::string&amp; format);
std::string format(const cpu_times&amp; times, short places = default_places);
} // namespace timer
} // namespace boost</pre>
</blockquote>
</td>
</tr>
</table>
<h3><a name="Default-format">Default format</a></h3>
<p>The default format is &quot; %ws wall, %us user + %ss system = %ts CPU (%p%)\n&quot;.</p>
<h3>Typedef <a name="nanosecond_type"><code>nanosecond_type</code></a></h3>
<p>The typedef <code>nanosecond_type</code> provides an implementation defined type capable
of representing nanoseconds. For POSIX and Windows systems, <code>
nanoseconds_type</code> is <code>boost::int_least64_t</code>.</p>
<p>The underlying type is not based on the Boost Date-Time or Chrono library to avoid a
dependency on a large library. This design choice may change at some future
date.</p>
<p>Although <code>nanosecond_type</code> is capable of representing one <b>
nanosecond</b>, the actual resolution of common operating system timers may be
much lower. For wall clock time on desktop systems circa 2010, resolution is
often no better than than one <b>microsecond</b>. For user and system time, typical
resolution is 15 <b>milliseconds</b> on Windows and 10 <b>milliseconds</b> on
POSIX.</p>
<h3><a name="cpu_times">Struct <code>cpu_times</code></a></h3>
<p>Struct <code>cpu_times</code> packages the elapsed wall clock time, user
process CPU time, and system process CPU time. See
<a href="#Current-time-values">Current time values</a> for definitions of the
source of these elapsed times.</p>
<pre><span style="background-color: #D7EEFF">void clear();</span></pre>
<blockquote>
<p><i>Effects:</i> <code>wall = user = system = 0LL</code>.</p>
</blockquote>
<h3><a name="Namespace-scope-functions">Namespace scope functions</a></h3>
<pre><span style="background-color: #D7EEFF">std::string </span><a name="format"><span style="background-color: #D7EEFF">format</span></a><span style="background-color: #D7EEFF">(const </span><a href="#cpu_times"><span style="background-color: #D7EEFF">cpu_times</span></a><span style="background-color: #D7EEFF">&amp; times, short places, const std::string&amp; format);
std::string </span><a name="format-2"><span style="background-color: #D7EEFF">format</span></a><span style="background-color: #D7EEFF">(const </span><a href="#cpu_times"><span style="background-color: #D7EEFF">cpu_times</span></a><span style="background-color: #D7EEFF">&amp; times, short places = default_places);</span></pre>
<blockquote>
<p><i>Overview: </i>Converts <code>times</code>'s values to strings representing
seconds to <code>places</code> decimal places, and inserts them into the return
string as controlled by <code>format</code>.</p>
<p><i>Remarks:</i> For the overload without the <code>format</code>
argument, the <a href="#Default-format">default format</a> is used as <code>format</code>.</p>
<p><i>Returns:</i> A string that is a copy of <code>format</code>, except that any
instances of the sequences shown below are replaced by the indicated value.
Times are reported in seconds,
shown to <code>std::max(0, std::min(default_places, 9))</code> decimal places. Percentage is reported to one
decimal place. [<i>Note:</i> percentage may exceed 100% due to differences in
how operating systems measure various times. <i>--end note</i>]</p>
<p><i><b><a name="Format-replacement-sequences">Format replacement sequences</a></b></i></p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td align="center" bgcolor="#D7EEFF"><b><i>Sequence</i></b></td>
<td align="center" bgcolor="#D7EEFF"><b><i>Replacement value</i></b></td>
</tr>
<tr>
<td align="center"><code>%w</code></td>
<td><code>times.wall</code></td>
</tr>
<tr>
<td align="center"><code>%u</code></td>
<td><code>times.user</code></td>
</tr>
<tr>
<td align="center"><code>%s</code></td>
<td><code>times.system</code></td>
</tr>
<tr>
<td align="center"><code>%t</code></td>
<td><code>times.user + times.system</code></td>
</tr>
<tr>
<td align="center"><code>%p</code></td>
<td>The percentage of <code>times.wall</code> represented by <code>
times.user + times.system</code></td>
</tr>
</table>
</blockquote>
<h3><a name="Class-cpu_timer">Class <code>cpu_timer</code></a></h3>
<p> <code>cpu_timer</code> objects measure wall clock elapsed time and process elapsed
time charged to the user and system.</p>
<p><i><b><a name="Current-time-values">Current time values</a></b></i> are the
current wall clock time, user process time, and system process time as provided
by the operating system:</p>
<ul>
<li>Wall clock time is time as would be measured by
an ordinary wristwatch or clock on the wall.</li>
<li>User process time is &quot;the CPU time charged for the
execution of user instructions of the calling process.&quot; See
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/times.html">
POSIX</a>.</li>
<li>System process time is &quot;the CPU time charged for
execution by the system on behalf of the calling process.&quot; See
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/times.html">
POSIX</a>.</li>
</ul>
<h3> <a name="cpu_timer-synopsis"> <code>cpu_timer</code> synopsis</a></h3>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td bgcolor="#D7EEFF">
<pre>
class <a name="cpu_timer">cpu_timer</a>
{
public:
// constructor
<a href="#cpu_timer-ctor">cpu_timer</a>() noexcept;
// compiler generated; shown for exposition only
~cpu_timer() noexcept = default;
cpu_timer(const cpu_timer&amp;)&nbsp;noexcept = default;
cpu_timer&amp; operator=(const cpu_timer&amp;) noexcept = default;
// observers
bool <a href="#is_stopped">is_stopped</a>() const noexcept;
cpu_times <a href="#elapsed">elapsed</a>() const noexcept;
std::string <a href="#cpu_timer-format">format</a>(int places, const std::string&amp; format) const;
std::string <a href="#cpu_timer-format">format</a>(int places = default_places) const;
// actions
void <a href="#start">start</a>() noexcept;
void <a href="#stop">stop</a>() noexcept;
void <a href="#resume">resume</a>() noexcept;
};</pre>
</td>
</tr>
</table>
<h3><a name="cpu_timer-constructors"><code>cpu_timer</code> constructor</a></h3>
<pre><span style="background-color: #D7EEFF"><a name="cpu_timer-ctor">cpu_timer</a>() noexcept;</span></pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of type <code>
cpu_timer</code>. Calls<code> start()</code>.</p>
</blockquote>
<h3><a name="cpu_timer-observers"><code>cpu_timer</code>
observers</a></h3>
<pre><span style="background-color: #D7EEFF">bool</span><span style="background-color: #D7EEFF"> <a name="is_stopped">is_stopped</a>() const noexcept;</span></pre>
<blockquote>
<p><i>Returns:</i> <code>true</code> if <a href="#stop">stop()</a> was the most recent
<a href="#cpu_timer-actions">action</a> function called,
otherwise <code>false</code>.</p>
</blockquote>
<pre><span style="background-color: #D7EEFF">cpu_times</span><span style="background-color: #D7EEFF"> <a name="elapsed">elapsed</a>() const noexcept;</span></pre>
<blockquote>
<p><i>Returns:</i> If <code>is_stopped()</code>, the accumulated elapsed times
as of the previous <a href="#stop">stop()</a>. Otherwise, the elapsed times
accumulated between the most recent call to <a href="#start">start()</a> or
<a href="#resume">resume()</a> and the <a href="#Current-time-values">current
time values</a>.</p>
</blockquote>
<pre><span style="background-color: #D7EEFF">std::string </span><a name="cpu_timer-format"><span style="background-color: #D7EEFF">format</span></a><span style="background-color: #D7EEFF">(int</span><span style="background-color: #D7EEFF"> places, const std::string&amp; format) const;
std::string </span><a name="cpu_timer-format-2"><span style="background-color: #D7EEFF">format</span></a><span style="background-color: #D7EEFF">(int</span><span style="background-color: #D7EEFF"> places = </span><span style="background-color: #D7EEFF">default_places</span><span style="background-color: #D7EEFF">) const;</span></pre>
<blockquote>
<p><i>Overview:</i> Returns a string for the current elapsed time as formatted
by the <a href="#format">format non-member function</a>.</p>
<p><i>Returns:</i> <code>boost::<a href="#format">timer::format</a>(<a href="#elapsed">elapsed</a>(), places<i>[, format]</i>)</code>.</p>
</blockquote>
<h3><a name="cpu_timer-actions"><code>cpu_timer</code>
actions</a></h3>
<pre><span style="background-color: #D7EEFF">void <a name="start">start</a>() noexcept;</span></pre>
<blockquote>
<p dir="ltr"><i>Effects:</i> Begins accumulating elapsed time as of the <a href="#Current-time-values">current time values</a>.</p>
<p><i>Postconditions:</i> <code>!is_stopped()</code>.</p>
</blockquote>
<pre><span style="background-color: #D7EEFF">void <a name="stop">stop</a>() noexcept;</span></pre>
<blockquote>
<p><i>Effects:</i> If <code>!is_stopped()</code>, stops accumulating elapsed
time as of the <a href="#Current-time-values">current time values</a>.</p>
<blockquote>
<p>[<i>Note:</i> This is observable via <code>elapsed()</code>. <i>-- end note</i>]</p>
</blockquote>
<p><i>Postconditions:</i> <code>is_stopped()</code>.</p>
</blockquote>
<pre><span style="background-color: #D7EEFF">void <a name="resume">resume</a>() noexcept;</span></pre>
<blockquote>
<p><i>Overview:</i> Restarts the timer, accumulating additional elapsed time.</p>
<p><i>Effects:</i> If <code>is_stopped()</code>, resumes accumulating
additional elapsed time, as of the <a href="#Current-time-values">current time values</a>. Otherwise, no effect.</p>
</blockquote>
<h3><a name="Class-auto_cpu_timer">Class <code>auto_cpu_timer</code></a></h3>
<p>Class <code>auto_cpu_timer</code> adds a <code>report()</code>
function to <code>class cpu_timer</code>, and automatically calls <code>report()</code>
on destruction.</p>
<h3> <a name="auto_cpu_timer-synopsis"> <code>auto_cpu_timer</code> synopsis</a></h3>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td bgcolor="#D7EEFF">
<pre>
class <a name="auto_cpu_timer">auto_cpu_timer</a> : public <a href="#cpu_timer">cpu_timer</a>
{
public:
explicit <a href="#auto_cpu_timer-1">auto_cpu_timer</a>(short places = default_places);
<a href="#auto_cpu_timer-2">auto_cpu_timer</a>(short places, const std::string&amp; format);
explicit <a href="#auto_cpu_timer-3">auto_cpu_timer</a>(const std::string&amp; format);
<a href="#auto_cpu_timer-4">auto_cpu_timer</a>(std::ostream&amp; os, short places, const std::string&amp; format);
explicit <a href="#auto_cpu_timer-5">auto_cpu_timer</a>(std::ostream&amp; os, short places = default_places);
<a href="#auto_cpu_timer-6">auto_cpu_timer</a>(std::ostream&amp; os, const std::string&amp; format);
<a href="#auto_cpu_timer-destructor">~auto_cpu_timer</a>() noexcept;
// compiler generated; shown for exposition only
auto_cpu_timer(const auto_cpu_timer&amp;) = default;
auto_cpu_timer&amp; operator=(const auto_cpu_timer&amp;) = default;
// <a href="#auto_cpu_timer-observers">observers</a>
std::ostream&amp; <a href="#ostream">ostream</a>() const noexcept;
short <a href="#places">places</a>() const noexcept;
const std::string&amp; <a href="#format_string">format_string</a>() const noexcept;
// <a href="#auto_cpu_timer-actions">actions</a>
void <a href="#report">report</a>();
};</pre>
</td>
</tr>
</table>
<p dir="ltr">[<i>Note:</i> Constructors without a <code>std::ostream&amp;</code>
argument argument imply <code>
std::cout</code>. An argument default is avoided as it would require including <code>&lt;iostream&gt;</code>,
with its high costs, even when the standard streams are not used. <i>--end note</i>]</p>
<h3><a name="auto_cpu_timer-constructors"><code>auto_cpu_timer</code> constructors</a></h3>
<pre><span style="background-color: #D7EEFF">explicit <a name="auto_cpu_timer-1">auto_cpu_timer</a>(short</span><span style="background-color: #D7EEFF"> places = </span><span style="background-color: #D7EEFF">default_places</span><span style="background-color: #D7EEFF">);
<a name="auto_cpu_timer-2">auto_cpu_timer</a>(short</span><span style="background-color: #D7EEFF"> places, const std::string&amp; format);
explicit <a name="auto_cpu_timer-3">auto_cpu_timer</a>(const</span><span style="background-color: #D7EEFF"> std::string&amp; format);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a name="auto_cpu_timer-4">auto_cpu_timer</a>(std::ostream</span><span style="background-color: #D7EEFF">&amp; </span><span style="background-color: #D7EEFF">os</span><span style="background-color: #D7EEFF">, short places, const std::string&amp; format);<br>explicit <a name="auto_cpu_timer-5">auto_cpu_timer</a>(std::ostream</span><span style="background-color: #D7EEFF">&amp; </span><span style="background-color: #D7EEFF">os</span><span style="background-color: #D7EEFF">, short places = </span><span style="background-color: #D7EEFF">default_places</span><span style="background-color: #D7EEFF">);<br> <a name="auto_cpu_timer-6">auto_cpu_timer</a>(std::ostream</span><span style="background-color: #D7EEFF">&amp; </span><span style="background-color: #D7EEFF">os</span><span style="background-color: #D7EEFF">, const std::string&amp; format);
</span></pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of type <code>
auto_cpu_timer</code> and stores the ostream, places, and format string data
needed to establish the postconditions.</p>
<p><i>Postconditions:</i></p>
<ul>
<li>For overloads with an <code>os</code> argument, <code>ostream() == os</code>.
Otherwise <code>ostream() == std::cout</code>.</li>
<li><code>places() == places</code>.</li>
<li>For overloads with a <code>format</code> argument, <code>format_string()
== format</code>. Otherwise <code>format_string() == std::cout</code></li>
</ul>
</blockquote>
<h3><a name="auto_cpu_timer-destructor"><code>auto_cpu_timer</code> destructor</a></h3>
<pre><span style="background-color: #D7EEFF">~</span><span style="background-color: #D7EEFF">auto_cpu_timer</span><span style="background-color: #D7EEFF">() noexcept;</span></pre>
<blockquote>
<p dir="ltr"><i>Effects: </i>If <code>!is_stopped()</code>, stop(), <a href="#report">
report()</a>.</p>
<p dir="ltr">[<i>Note:</i> Because the function is <code>noexcept</code>,
implementation must ensure no exception
escapes. <i>--end note</i>]</p>
</blockquote>
<h3><a name="auto_cpu_timer-observers">auto_cpu_timer observers</a></h3>
<p>The observers allow testing of constructor postconditions and specification
of other functionality without resorting to &quot;for exposition only&quot; private
members.</p>
<pre><span style="background-color: #D7EEFF">std::ostream&amp; <a name="ostream">ostream</a>() const noexcept;</span></pre>
<blockquote>
<p><i>Returns:</i> The ostream stored by construction or subsequent copy
assignment.</p>
</blockquote>
<pre><span style="background-color: #D7EEFF">short <a name="places">places</a>() const noexcept;</span></pre>
<blockquote>
<p><i>Returns:</i> The places stored by construction or subsequent copy
assignment.</p>
</blockquote>
<pre><span style="background-color: #D7EEFF">const std::string&amp; <a name="format_string">format_string</a>() const noexcept;</span></pre>
<blockquote>
<p><i>Returns:</i> The format string stored by construction or subsequent copy
assignment.</p>
</blockquote>
<h3><a name="auto_cpu_timer-actions"><code>auto_cpu_timer</code> actions</a></h3>
<pre><span style="background-color: #D7EEFF">void <a name="report">report</a>();</span></pre>
<blockquote>
<p><i>Effects: </i>As if:</p>
<blockquote>
<pre>ostream() &lt;&lt; timer::format(elapsed(), places(), format_string());</pre>
</blockquote>
<p>[<i>Note: </i>It may be desirable to call <code>stop()</code> before
calling <code>report()</code> because doing I/O while the
timer is running might produce misleading results. <code>resume()</code> may
be called afterwards to continue timing. <i>--end note</i>]</p>
</blockquote>
<h2><a name="History">History</a></h2>
<p>Beman Dawes and Rob Stewart developed version 2 of the library.</p>
<p>Beman did the initial development. Rob contributed many corrections, comments, and suggestions. In
particular, he suggested the <code>resume()</code> and <code>format()</code>
functions, resulting in improved ease-of-use for several use cases.</p>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
<p>Comments and suggestions came from Greg Rubino, Dave Abrahams, Vicente
Botet, and John Maddock.</p>
<hr>
<p><font size="2">Revised:
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->08 October 2011<!--webbot bot="Timestamp" endspan i-checksum="32193" --></font></p>
<p><font size="2"><EFBFBD> Copyright Beman Dawes, 2006<br>
<EFBFBD> Copyright Beman Dawes and Robert Stewart, 2011</font></p>
<p><font size="2">Distributed under the Boost Software License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/ LICENSE_1_0.txt</a></font></p>
</body>
</html>

View File

@@ -0,0 +1,86 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Boost Timer Library</title>
<style type="text/css">
ins {background-color:#A0FFA0}
del {background-color:#FFA0A0}
body
{
font-family: sans-serif;
max-width : 8.5in;
margin: 1em;
}
</style>
</head>
<body>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="750">
<tr>
<td width="300">
<a href="../../../index.htm">
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="300" height="86" border="0"></a></td>
<td align="middle" width="430">
<font size="7">Timer Library<br>
Version 2</font>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
<tr>
<td><a href="index.html">Timer Home</a> &nbsp;&nbsp;
<a href="cpu_timers.html">CPU timers</a> &nbsp;&nbsp;
<a href="original_timer.html">Original timers</a> &nbsp;&nbsp;
</td>
</tr>
</table>
<p>&quot;How long does my C++ code take to run?&quot;<p>The Boost Timer library
answers that question and does so portably, with as little as one #include and one
additional line of code.<p>The Boost Timer library has two distinct sets of
components:<ul>
<li>If you are new to the library, please go directly to the version 2
<a href="cpu_timers.html">CPU timers</a> page.</li>
<li>If you are interested in
the original library, now deprecated, read on below.</li>
</ul>
<h2>
<a href="cpu_timers.html">CPU timers</a></h2>
<p>These version 2 components conform to current Boost practice:</p>
<ul>
<li>The interfaces and their semantics are the same across all platforms.</li>
<li>The internal implementation uses operating system specific APIs to achieve
higher precision and supply functionality not otherwise available.&nbsp; </li>
<li>The headers live in a sub-directory, <code>&lt;boost/timer/...&gt;</code>.</li>
<li>The content is in a sub-namespace, <code>boost::timer</code>.</li>
</ul>
<h2 dir="ltr">
<a href="original_timer.html">Original timers</a></h2>
<p>These version 1 components are deprecated. They date from the earliest days
of Boost and do not conform to current Boost practice:</p>
<ul>
<li>The interfaces are the same across all platforms, but the semantics differ
according to platform. Wall-clock time is measured on Windows, while CPU time
is measured on POSIX-like systems.</li>
<li>The internal implementation uses only C/C++ standard library functions, so
cannot supply desirable precision and functionality.</li>
<li>The headers live in the main Boost header directory.</li>
<li>The content are in namespace <code>boost</code>.</li>
</ul>
<hr>
<p><font size="2">Revised:
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->07 October 2011<!--webbot bot="Timestamp" endspan i-checksum="32191" --></font></p>
<p><font size="2"><EFBFBD> Copyright Beman Dawes&nbsp; 2001, 2011</font></p>
<p><font size="2">Distributed under the Boost Software License, Version 1.0. See
</font>
<a href="http://www.boost.org/LICENSE_1_0.txt"><font size="2">www.boost.org/LICENSE_1_0.txt</font></a></p>
</body>
</html>

View File

@@ -0,0 +1,267 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Original Timers</title>
<style type="text/css">
ins {background-color:#A0FFA0}
del {background-color:#FFA0A0}
body
{
font-family: sans-serif;
max-width : 8.5in;
margin: 1em;
}
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="750">
<tr>
<td width="300">
<a href="../../../index.htm">
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="300" height="86" border="0"></a></td>
<td align="middle" width="430">
<font size="7">Timer Library<br>
Original Timers and Progress Display</font></td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
<tr>
<td><a href="index.html">Timer Home</a> &nbsp;&nbsp;
<a href="cpu_timers.html">CPU timers</a> &nbsp;&nbsp;
<a href="original_timer.html">Original timers</a> &nbsp;&nbsp;
</td>
</tr>
</table>
<p></p>
<center>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="80%">
<tr>
<td width="100%" bgcolor="#FFFF66">
<p><i><b>These timers are deprecated.</b></i> They date from the earliest days
of Boost and do not conform
to current Boost practice.</p>
<ul>
<li>The interfaces are the same across all platforms, but the semantics differ
according to platform. Wall-clock time is measured on Windows, while CPU time
is measured on POSIX-like systems.</li>
<li>The internal implementation uses only C/C++ standard library functions, so
cannot supply desirable precision and functionality.</li>
<li>The headers live in the main Boost header directory.</li>
<li>The content are in namespace <code>boost</code>.</li>
</ul>
Please see the Version 2
<a href="cpu_timers.html">CPU timers</a> for replacements that conform to
current Boost practice.</td>
</tr>
</table>
</center>
<p>The timer library provides two headers and three classes: </p>
<blockquote>
<table border="1" cellpadding="5">
<tr>
<td><b>Header</b></td>
<td><b>Class</b></td>
<td><b>Functionality</b></td>
</tr>
<tr>
<td><a href="../../../boost/timer.hpp">timer.hpp</a></td>
<td><a href="#Class timer">timer</a></td>
<td>Measure elapsed time.</td>
</tr>
<tr>
<td><a href="../../../boost/progress.hpp">progress.hpp</a></td>
<td><a href="#Class progress_timer">progress_timer</a></td>
<td>Measure elapsed time (using timer), display on destruction.</td>
</tr>
<tr>
<td><a href="../../../boost/progress.hpp">progress.hpp</a></td>
<td><a href="#Class progress_display">progress_display</a></td>
<td>Display an indication of progress toward a known goal.</td>
</tr>
</table>
</blockquote>
<p>The objective in designing these classes was fairly limited - they are
intended for simple uses like timing and reporting progress for programmer's
tests or batch job streams. The specifications of the progress classes are
worded in very general terms to permit alternate implementations such as for
graphical user interfaces.</p>
<h2><a name="Class timer">Class timer</a></h2>
<p>Class timer measures elapsed time.&nbsp; It is generally useful for minor
timing tasks.&nbsp; Its supplied implementation offers moderate portability at
the cost of depending on the unknown accuracy and precision of the C Standard
Library clock() function.&nbsp; The maximum measurable elapsed time may be as
low as 596.5 hours (or even less) for the supplied implementation. Because of
these limitations, this timer cannot be depended upon to
be robust, and should not be used if that is of any concern.</p>
<h3>Synopsis</h3>
<pre>#include &lt;<a href="../../../boost/timer.hpp">boost/timer.hpp</a>&gt;
namespace boost {
class timer {
public:
timer(); // postcondition: elapsed()==0
// compiler generated copy constructor, copy assignment, and dtor apply
void restart(); // post: elapsed()==0
double elapsed() const; // return elapsed time in seconds
double elapsed_max() const; // return estimated maximum value for elapsed()
// Portability warning: elapsed_max() may return too high a value on systems
// where std::clock_t overflows or resets at surprising values.
double elapsed_min() const; // return minimum value for elapsed()
}; // timer
} // namespace boost</pre>
<h3>Exception safety</h3>
<p>The constructors may throw <code>std::bad_alloc</code>.&nbsp; No other member
functions throw exceptions.</p>
<h3>Future directions</h3>
<p>There was a very reasonable request from Ed Brey for a method of determining
the maximum value which may be returned by elapsed(), but there isn't a way to do so
portably. The issue has been raised with the group working on extended time functionality for the C language. A solution
may be years in the future. In the meantime, elapsed_max() provides an
approximation.</p>
<h2><a name="Class progress_timer">Class progress_timer</a></h2>
<p>Class progress_timer automatically measures elapsed time, and then on
destruction displays an elapsed time message at an appropriate place in an appropriate form.&nbsp;
The supplied implementation defaults to a character display on std::cout.</p>
<p>Class progress_timer is often used to time program execution.&nbsp; Its use is as simple as:</p>
<blockquote>
<pre>#include &lt;<a href="../../../boost/progress.hpp">boost/progress.hpp</a>&gt;
int main()
{
progress_timer t; // start timing
// do something ...
return 0;
}</pre>
</blockquote>
<p>Which will produce some appropriate output, for example:</p>
<blockquote>
<pre>1.23 s</pre>
</blockquote>
<p>Note that &quot;s&quot; is the official System International d'Unit<69>s
abbreviation for seconds.</p>
<h3>Synopsis</h3>
<pre>#include &lt;<a href="../../../boost/progress.hpp">boost/progress.hpp</a>&gt;
namespace boost {
class progress_timer : public <a href="#Class timer">timer</a>, <a href="../../core/doc/html/core/noncopyable.html">noncopyable</a> {
public:
progress_timer();
progress_timer( std::ostream&amp; os ); // os is hint; implementation may ignore
~progress_timer();
}; // progress_display
} // namespace boost</pre>
<h3>Exception safety</h3>
<p>The constructors may throw <code>std::bad_alloc</code>.&nbsp; No other member
functions throw exceptions.</p>
<h2><a name="Class progress_display">Class progress_display</a></h2>
<p>Class progress_display displays an appropriate indication of progress toward
a predefined goal at an appropriate place in an appropriate form.&nbsp; This
meets a human need to know if a program is progressing.</p>
<p>For example, if a lengthy computation must be done on a std::map&lt;&gt;
named big_map, the follow code would display an indication of progress:</p>
<pre> progress_display show_progress( big_map.size() );
for ( big_map_t::iterator itr = big_map:begin();
itr != big_map.end(); ++itr )
{
// do the computation
...
++show_progress;
}</pre>
<p>After 70% of the elements have been processed, the display might look
something like this:</p>
<blockquote>
<pre>0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
************************************</pre>
</blockquote>
<h2>Synopsis</h2>
<pre>#include &lt;boost/progress.hpp&gt;
namespace boost {
class progress_display : <a href="../../core/doc/html/core/noncopyable.html">noncopyable</a> {
public:
progress_display( unsigned long expected_count );
// Effects: restart(expected_count)
progress_display( unsigned long expected_count,
std::ostream&amp; os, // os is hint; implementation may ignore
const std::string &amp; s1 = &quot;\n&quot;, //leading strings
const std::string &amp; s2 = &quot;&quot;,
const std::string &amp; s3 = &quot;&quot; )
// Effects: save copy of leading strings, restart(expected_count)
void restart( unsigned long expected_count );
// Effects: display appropriate scale on three lines,
// prefaced by stored copy of s1, s2, s3, respectively, from constructor
// Postconditions: count()==0, expected_count()==expected_count
unsigned long operator+=( unsigned long increment )
// Effects: Display appropriate progress tic if needed.
// Postconditions: count()== original count() + increment
// Returns: count().
unsigned long operator++()
// Returns: operator+=( 1 ).
unsigned long count() const
// Returns: The internal count.
unsigned long expected_count() const
// Returns: The expected_count from the constructor.
}; // progress_display
} // namespace boost</pre>
<h3>Exception safety</h3>
<p>All member functions except count() and expected_count() do output, and so in
theory may throw exceptions.&nbsp; In practice it seems an exception being
thrown is pretty unlikely, and probably implies such serious problems that an
exception is warranted.&nbsp; Note that there is no explicit destructor, so the
destructor throwing is not an issue.</p>
<h2>History</h2>
<p>These classes are descended from older C++ and C functionality found useful
by programmers for many years. Via the Boost mailing list, Reid Sweatman
suggested separating the more widely useful timer class from the more targeted
progress classes. Sean Corfield suggested allowing output to any ostream.&nbsp;
Dave Abrahams, Valentin Bonnard, Ed Brey, Andy Glew, and Dietmar K<>hl also
provided useful comments.&nbsp; Ed Brey suggested timer::elapsed_max(). John
Maddock suggested timer::elapsed_min(). Toon Knapen suggested the optional
leading strings, to allow for labeling the progress display</p>
<h2>Rationale</h2>
<p>The early versions of the timer classes had separate implementation
files.&nbsp; This caused problems for users not wishing to build libraries,
caused difficulties building DLL's (because of cascaded use of other libraries
which in turn brought illuminated compiler deficiencies), and caused the classes
not to be used even when clearly applicable.&nbsp; Thus the implementation was
changed to all inline code.</p>
<p>There have been several requests for platform specific implementations to use
supposedly high-performance timers from the operating system API.&nbsp; John
Maddock submitted an implementation using the Win32 API.&nbsp; Tests showed that
while the precision of these timers was high, the latency was sometimes very
much higher than for the std::clock() function, and that is very bad.&nbsp;
Furthermore, results using the Win32 API were very dependent on both the
compiler (Microsoft and Borland were tested) and the operating system version
(Windows NT, Windows 95, etc.)&nbsp; Thus the std::clock() function was much
more reliable, and so was retained even on this platform with its own timer API.</p>
<hr>
<p><font size="2">Revised:
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->04 October 2011<!--webbot bot="Timestamp" endspan i-checksum="32185" --></font></p>
<p><font size="2"><EFBFBD> Copyright Beman Dawes 1999.</font></p>
<p><font size="2">Distributed under the Boost Software License, Version 1.0. See
</font>
<a href="http://www.boost.org/LICENSE_1_0.txt"><font size="2">www.boost.org/LICENSE_1_0.txt</font></a></p>
</body>
</html>

View File

@@ -0,0 +1,19 @@
// auto_cpu_timer_example.cpp ------------------------------------------------------//
// Copyright Beman Dawes 2006
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include <boost/timer/timer.hpp>
#include <cmath>
int main()
{
boost::timer::auto_cpu_timer t;
for ( long i = 0; i < 100000000; ++i )
std::sqrt( 123.456L ); // burn some time
return 0;
}

View File

@@ -0,0 +1,47 @@
// timex: timed execution program ------------------------------------------//
// Copyright Beman Dawes 2007
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/timer for documentation.
#include <boost/timer/timer.hpp>
#include <cstdlib>
#include <string>
#include <iostream>
int main( int argc, char * argv[] )
{
if ( argc == 1 )
{
std::cout << "invoke: timex [-v] command [args...]\n"
" command will be executed and timings displayed\n"
" -v option causes command and args to be displayed\n";
return 1;
}
std::string s;
bool verbose = false;
if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
{
verbose = true;
++argv;
--argc;
}
for ( int i = 1; i < argc; ++i )
{
if ( i > 1 ) s += ' ';
s += argv[i];
}
if ( verbose )
{ std::cout << "command: \"" << s.c_str() << "\"\n"; }
boost::timer::auto_cpu_timer t(" %ws elapsed wall-clock time\n");
return std::system( s.c_str() );
}

View File

@@ -0,0 +1,145 @@
// boost progress.hpp header file ------------------------------------------//
// Copyright Beman Dawes 1994-99. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/timer for documentation.
// Revision History
// 1 Dec 01 Add leading progress display strings (suggested by Toon Knapen)
// 20 May 01 Introduce several static_casts<> to eliminate warning messages
// (Fixed by Beman, reported by Herve Bronnimann)
// 12 Jan 01 Change to inline implementation to allow use without library
// builds. See docs for more rationale. (Beman Dawes)
// 22 Jul 99 Name changed to .hpp
// 16 Jul 99 Second beta
// 6 Jul 99 Initial boost version
#ifndef BOOST_PROGRESS_HPP
#define BOOST_PROGRESS_HPP
#include <boost/config/header_deprecated.hpp>
BOOST_HEADER_DEPRECATED( "the facilities in <boost/timer/timer.hpp> or <boost/timer/progress_display.hpp>" )
#include <boost/timer.hpp>
#include <boost/noncopyable.hpp>
#include <boost/cstdint.hpp> // for uintmax_t
#include <iostream> // for ostream, cout, etc
#include <string> // for string
namespace boost {
// progress_timer ----------------------------------------------------------//
// A progress_timer behaves like a timer except that the destructor displays
// an elapsed time message at an appropriate place in an appropriate form.
class progress_timer : public timer, private noncopyable
{
public:
explicit progress_timer( std::ostream & os = std::cout )
// os is hint; implementation may ignore, particularly in embedded systems
: timer(), noncopyable(), m_os(os) {}
~progress_timer()
{
// A) Throwing an exception from a destructor is a Bad Thing.
// B) The progress_timer destructor does output which may throw.
// C) A progress_timer is usually not critical to the application.
// Therefore, wrap the I/O in a try block, catch and ignore all exceptions.
try
{
// use istream instead of ios_base to workaround GNU problem (Greg Chicares)
std::istream::fmtflags old_flags = m_os.setf( std::istream::fixed,
std::istream::floatfield );
std::streamsize old_prec = m_os.precision( 2 );
m_os << elapsed() << " s\n" // "s" is System International d'Unites std
<< std::endl;
m_os.flags( old_flags );
m_os.precision( old_prec );
}
catch (...) {} // eat any exceptions
} // ~progress_timer
private:
std::ostream & m_os;
};
// progress_display --------------------------------------------------------//
// progress_display displays an appropriate indication of
// progress at an appropriate place in an appropriate form.
// NOTE: (Jan 12, 2001) Tried to change unsigned long to boost::uintmax_t, but
// found some compilers couldn't handle the required conversion to double.
// Reverted to unsigned long until the compilers catch up.
class progress_display : private noncopyable
{
public:
explicit progress_display( unsigned long expected_count_,
std::ostream & os = std::cout,
const std::string & s1 = "\n", //leading strings
const std::string & s2 = "",
const std::string & s3 = "" )
// os is hint; implementation may ignore, particularly in embedded systems
: noncopyable(), m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count_); }
void restart( unsigned long expected_count_ )
// Effects: display appropriate scale
// Postconditions: count()==0, expected_count()==expected_count_
{
_count = _next_tic_count = _tic = 0;
_expected_count = expected_count_;
m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n"
<< m_s2 << "|----|----|----|----|----|----|----|----|----|----|"
<< std::endl // endl implies flush, which ensures display
<< m_s3;
if ( !_expected_count ) _expected_count = 1; // prevent divide by zero
} // restart
unsigned long operator+=( unsigned long increment )
// Effects: Display appropriate progress tic if needed.
// Postconditions: count()== original count() + increment
// Returns: count().
{
if ( (_count += increment) >= _next_tic_count ) { display_tic(); }
return _count;
}
unsigned long operator++() { return operator+=( 1 ); }
unsigned long count() const { return _count; }
unsigned long expected_count() const { return _expected_count; }
private:
std::ostream & m_os; // may not be present in all imps
const std::string m_s1; // string is more general, safer than
const std::string m_s2; // const char *, and efficiency or size are
const std::string m_s3; // not issues
unsigned long _count, _expected_count, _next_tic_count;
unsigned int _tic;
void display_tic()
{
// use of floating point ensures that both large and small counts
// work correctly. static_cast<>() is also used several places
// to suppress spurious compiler warnings.
unsigned int tics_needed = static_cast<unsigned int>((static_cast<double>(_count)
/ static_cast<double>(_expected_count)) * 50.0);
do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed );
_next_tic_count =
static_cast<unsigned long>((_tic/50.0) * static_cast<double>(_expected_count));
if ( _count == _expected_count ) {
if ( _tic < 51 ) m_os << '*';
m_os << std::endl;
}
} // display_tic
};
} // namespace boost
#endif // BOOST_PROGRESS_HPP

View File

@@ -0,0 +1,75 @@
// boost timer.hpp header file ---------------------------------------------//
// Copyright Beman Dawes 1994-99. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/timer for documentation.
// Revision History
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
// 12 Jan 01 Change to inline implementation to allow use without library
// builds. See docs for more rationale. (Beman Dawes)
// 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock)
// 16 Jul 99 Second beta
// 6 Jul 99 Initial boost version
#ifndef BOOST_TIMER_HPP
#define BOOST_TIMER_HPP
#include <boost/config/header_deprecated.hpp>
BOOST_HEADER_DEPRECATED( "the facilities in <boost/timer/timer.hpp>" )
#include <boost/config.hpp>
#include <ctime>
#include <boost/limits.hpp>
# ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::clock_t; using ::clock; }
# endif
namespace boost {
// timer -------------------------------------------------------------------//
// A timer object measures elapsed time.
// It is recommended that implementations measure wall clock rather than CPU
// time since the intended use is performance measurement on systems where
// total elapsed time is more important than just process or CPU time.
// Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
// due to implementation limitations. The accuracy of timings depends on the
// accuracy of timing information provided by the underlying platform, and
// this varies a great deal from platform to platform.
class timer
{
public:
timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
// timer( const timer& src ); // post: elapsed()==src.elapsed()
// ~timer(){}
// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
void restart() { _start_time = std::clock(); } // post: elapsed()==0
double elapsed() const // return elapsed time in seconds
{ return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
double elapsed_max() const // return estimated maximum value for elapsed()
// Portability warning: elapsed_max() may return too high a value on systems
// where std::clock_t overflows or resets at surprising values.
{
return (double((std::numeric_limits<std::clock_t>::max)())
- double(_start_time)) / double(CLOCKS_PER_SEC);
}
double elapsed_min() const // return minimum value for elapsed()
{ return double(1)/double(CLOCKS_PER_SEC); }
private:
std::clock_t _start_time;
}; // timer
} // namespace boost
#endif // BOOST_TIMER_HPP

View File

@@ -0,0 +1,69 @@
// boost/timer/config.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 2003, 2006, 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/timer for documentation.
#ifndef BOOST_TIMER_CONFIG_HPP
#define BOOST_TIMER_CONFIG_HPP
#include <boost/config.hpp>
#include <boost/system/api_config.hpp>
// This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
// enable dynamic or static linking as requested --------------------------------------//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TIMER_DYN_LINK)
# if defined(BOOST_TIMER_SOURCE)
# define BOOST_TIMER_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_TIMER_DECL BOOST_SYMBOL_IMPORT
# endif
#else
# define BOOST_TIMER_DECL
#endif
// enable automatic library variant selection ----------------------------------------//
#if !defined(BOOST_TIMER_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_TIMER_NO_LIB)
//
// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
//
#define BOOST_LIB_NAME boost_timer
//
// If we're importing code from a dll, then tell auto_link.hpp about it:
//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TIMER_DYN_LINK)
# define BOOST_DYN_LINK
#endif
//
// And include the header that does the work:
//
#include <boost/config/auto_link.hpp>
// We also need to autolink to the Chrono library; even though
// it's not used in the interface, and no Chrono header is included,
// it's used in the implementation and is necessary in order to link
#if !defined(BOOST_CHRONO_NO_LIB)
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CHRONO_DYN_LINK)
# define BOOST_DYN_LINK
#endif
#define BOOST_LIB_NAME boost_chrono
#include <boost/config/auto_link.hpp>
#endif // !defined(BOOST_CHRONO_NO_LIB)
#endif // auto-linking disabled
#endif // BOOST_TIMER_CONFIG_HPP

View File

@@ -0,0 +1,90 @@
// Copyright Beman Dawes 1994-99.
// Copyright Peter Dimov 2019.
// Distributed under the Boost Software License, Version 1.0.
// (http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/timer for documentation.
#ifndef BOOST_TIMER_PROGRESS_DISPLAY_HPP_INCLUDED
#define BOOST_TIMER_PROGRESS_DISPLAY_HPP_INCLUDED
#include <boost/noncopyable.hpp>
#include <iostream> // for ostream, cout, etc
#include <string> // for string
namespace boost {
namespace timer {
// progress_display --------------------------------------------------------//
// progress_display displays an appropriate indication of
// progress at an appropriate place in an appropriate form.
class progress_display : private noncopyable
{
public:
explicit progress_display( unsigned long expected_count_,
std::ostream & os = std::cout,
const std::string & s1 = "\n", //leading strings
const std::string & s2 = "",
const std::string & s3 = "" )
// os is hint; implementation may ignore, particularly in embedded systems
: noncopyable(), m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count_); }
void restart( unsigned long expected_count_ )
// Effects: display appropriate scale
// Postconditions: count()==0, expected_count()==expected_count_
{
_count = _next_tic_count = _tic = 0;
_expected_count = expected_count_;
m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n"
<< m_s2 << "|----|----|----|----|----|----|----|----|----|----|"
<< std::endl // endl implies flush, which ensures display
<< m_s3;
if ( !_expected_count ) _expected_count = 1; // prevent divide by zero
} // restart
unsigned long operator+=( unsigned long increment )
// Effects: Display appropriate progress tic if needed.
// Postconditions: count()== original count() + increment
// Returns: count().
{
if ( (_count += increment) >= _next_tic_count ) { display_tic(); }
return _count;
}
unsigned long operator++() { return operator+=( 1 ); }
unsigned long count() const { return _count; }
unsigned long expected_count() const { return _expected_count; }
private:
std::ostream & m_os; // may not be present in all imps
const std::string m_s1; // string is more general, safer than
const std::string m_s2; // const char *, and efficiency or size are
const std::string m_s3; // not issues
unsigned long _count, _expected_count, _next_tic_count;
unsigned int _tic;
void display_tic()
{
// use of floating point ensures that both large and small counts
// work correctly. static_cast<>() is also used several places
// to suppress spurious compiler warnings.
unsigned int tics_needed = static_cast<unsigned int>((static_cast<double>(_count)
/ static_cast<double>(_expected_count)) * 50.0);
do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed );
_next_tic_count =
static_cast<unsigned long>((_tic/50.0) * static_cast<double>(_expected_count));
if ( _count == _expected_count ) {
if ( _tic < 51 ) m_os << '*';
m_os << std::endl;
}
} // display_tic
};
} // namespace timer
} // namespace boost
#endif // BOOST_TIMER_PROGRESS_DISPLAY_HPP_INCLUDED

View File

@@ -0,0 +1,129 @@
// boost/timer/timer.hpp -------------------------------------------------------------//
// Copyright Beman Dawes 1994-2007, 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_TIMER_TIMER_HPP
#define BOOST_TIMER_TIMER_HPP
#include <boost/timer/config.hpp>
#include <boost/cstdint.hpp>
#include <string>
#include <cstring>
#include <ostream>
#include <boost/config/abi_prefix.hpp> // must be the last #include
# if defined(_MSC_VER)
# pragma warning(push) // Save warning settings
# pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
# endif // needs to have dll-interface...
//--------------------------------------------------------------------------------------//
namespace boost
{
namespace timer
{
class cpu_timer;
class auto_cpu_timer;
typedef boost::int_least64_t nanosecond_type;
struct cpu_times
{
nanosecond_type wall;
nanosecond_type user;
nanosecond_type system;
void clear() { wall = user = system = 0; }
};
const short default_places = 6;
BOOST_TIMER_DECL
std::string format(const cpu_times& times, short places, const std::string& format);
BOOST_TIMER_DECL
std::string format(const cpu_times& times, short places = default_places);
// cpu_timer -------------------------------------------------------------------------//
class BOOST_TIMER_DECL cpu_timer
{
public:
// constructor
cpu_timer() BOOST_NOEXCEPT { start(); }
// observers
bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; }
cpu_times elapsed() const BOOST_NOEXCEPT; // does not stop()
std::string format(short places, const std::string& format) const
{ return ::boost::timer::format(elapsed(), places, format); }
std::string format(short places = default_places) const
{ return ::boost::timer::format(elapsed(), places); }
// actions
void start() BOOST_NOEXCEPT;
void stop() BOOST_NOEXCEPT;
void resume() BOOST_NOEXCEPT;
private:
cpu_times m_times;
bool m_is_stopped;
};
// auto_cpu_timer --------------------------------------------------------------------//
class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
{
public:
// Explicit defaults for os are not provided to avoid including <iostream>, which has
// high costs even when the standard streams are not actually used. Explicit defaults
// for format are not provided to avoid order-of-dynamic-initialization issues with a
// std::string.
explicit auto_cpu_timer(short places = default_places); // #1
auto_cpu_timer(short places, const std::string& format); // #2
explicit auto_cpu_timer(const std::string& format); // #3
auto_cpu_timer(std::ostream& os, short places,
const std::string& format) // #4
: m_places(places), m_os(&os), m_format(format)
{ start(); }
explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5
auto_cpu_timer(std::ostream& os, const std::string& format) // #6
: m_places(default_places), m_os(&os), m_format(format)
{ start(); }
~auto_cpu_timer();
// observers
// not particularly useful to users, but allow testing of constructor
// postconditions and ease specification of other functionality without resorting
// to "for exposition only" private members.
std::ostream& ostream() const { return *m_os; }
short places() const { return m_places; }
const std::string& format_string() const { return m_format; }
// actions
void report();
private:
short m_places;
std::ostream* m_os; // stored as ptr so compiler can generate operator=
std::string m_format;
};
} // namespace timer
} // namespace boost
# if defined(_MSC_VER)
# pragma warning(pop) // restore warning settings.
# endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_TIMER_TIMER_HPP

View File

@@ -0,0 +1,14 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=doc/index.html">
</head>
<body>
Automatic redirection failed, please go to <a href="doc/index.html">doc/index.html</a>.
<hr>
<p>&copy; Copyright Beman Dawes, 2003, 2011</p>
<p> Distributed under the Boost Software
License, Version 1.0.</p>
<p> See <a href="http://www.boost.org/LICENSE_1_0.txt">
www.boost.org/LICENSE_1_0.txt</a></p>
</body>
</html>

View File

@@ -0,0 +1,15 @@
{
"key": "timer",
"name": "Timer",
"authors": [
"Beman Dawes"
],
"description": "Event timer, progress timer, and progress display classes.",
"category": [
"Miscellaneous"
],
"maintainers": [
"Peter Dimov <pdimov -at- gmail.com>"
],
"cxxstd": "03"
}

View File

@@ -0,0 +1,46 @@
// boost auto_timers_construction.cpp ------------------------------------------------//
// Copyright Beman Dawes 2007, 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/timer for documentation.
//--------------------------------------------------------------------------------------//
// These constructors are in a separate file so that this translation unit will
// not be linked in except when one of the constructors is actually used. This
// is important since header <iostream> is required, and it incurs the cost of
// the standard stream objects even if they are not used.
//--------------------------------------------------------------------------------------//
// define BOOST_TIMER_SOURCE so that <boost/timer/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_TIMER_SOURCE
#include <boost/timer/timer.hpp>
#include <iostream>
namespace
{
// CAUTION: must be identical to same constant in cpu_timer.cpp
const std::string default_fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n");
}
namespace boost
{
namespace timer
{
auto_cpu_timer::auto_cpu_timer(short places) // #1
: m_places(places), m_os(&std::cout), m_format(default_fmt) { start(); }
auto_cpu_timer::auto_cpu_timer(short places, const std::string& format) // #2
: m_places(places), m_os(&std::cout), m_format(format) { start(); }
auto_cpu_timer::auto_cpu_timer(const std::string& format) // #3
: m_places(default_places), m_os(&std::cout), m_format(format) { start(); }
} // namespace timer
} // namespace boost

View File

@@ -0,0 +1,268 @@
// boost cpu_timer.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 1994-2006, 2011
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/timer for documentation.
//--------------------------------------------------------------------------------------//
// define BOOST_TIMER_SOURCE so that <boost/timer/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_TIMER_SOURCE
#include <boost/timer/timer.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/io/ios_state.hpp>
#include <boost/throw_exception.hpp>
#include <boost/cerrno.hpp>
#include <boost/predef.h>
#include <cstring>
#include <sstream>
#include <cassert>
# if defined(BOOST_WINDOWS_API)
# include <windows.h>
# elif defined(BOOST_POSIX_API)
# include <unistd.h>
# include <sys/times.h>
# else
# error unknown API
# endif
using boost::timer::nanosecond_type;
using boost::timer::cpu_times;
namespace
{
void show_time(const cpu_times& times,
std::ostream& os, const std::string& fmt, short places)
// NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
// be as low as 10, although will be 15 for many common platforms.
{
if (places > 9)
places = 9;
else if (places < 0)
places = boost::timer::default_places;
boost::io::ios_flags_saver ifs(os);
boost::io::ios_precision_saver ips(os);
os.setf(std::ios_base::fixed, std::ios_base::floatfield);
os.precision(places);
const double sec = 1000000000.0L;
nanosecond_type total = times.system + times.user;
double wall_sec = static_cast<double>(times.wall) / sec;
double total_sec = static_cast<double>(total) / sec;
for (const char* format = fmt.c_str(); *format; ++format)
{
if (*format != '%' || !*(format+1) || !std::strchr("wustp", *(format+1)))
os << *format; // anything except % followed by a valid format character
// gets sent to the output stream
else
{
++format;
switch (*format)
{
case 'w':
os << wall_sec;
break;
case 'u':
os << static_cast<double>(times.user) / sec;
break;
case 's':
os << static_cast<double>(times.system) / sec;
break;
case 't':
os << total_sec;
break;
case 'p':
os.precision(1);
if (wall_sec > 0.001L && total_sec > 0.001L)
os << (total_sec/wall_sec) * 100.0;
else
os << "n/a";
os.precision(places);
break;
}
}
}
}
# if defined(BOOST_POSIX_API)
boost::int_least64_t tick_factor_()
{
boost::int_least64_t tf = ::sysconf( _SC_CLK_TCK );
if( tf <= 0 ) return -1;
tf = INT64_C(1000000000) / tf; // compute factor
if( tf == 0 ) tf = -1;
return tf;
}
boost::int_least64_t tick_factor() // multiplier to convert ticks
// to nanoseconds; -1 if unknown
{
static boost::int_least64_t tf = tick_factor_();
return tf;
}
# endif
void get_cpu_times(boost::timer::cpu_times& current)
{
boost::chrono::duration<boost::int64_t, boost::nano>
x (boost::chrono::high_resolution_clock::now().time_since_epoch());
current.wall = x.count();
# if defined(BOOST_WINDOWS_API)
# if BOOST_PLAT_WINDOWS_DESKTOP || defined(__CYGWIN__)
FILETIME creation, exit;
if (::GetProcessTimes(::GetCurrentProcess(), &creation, &exit,
(LPFILETIME)&current.system, (LPFILETIME)&current.user))
{
current.user *= 100; // Windows uses 100 nanosecond ticks
current.system *= 100;
}
else
# endif
{
current.system = current.user = boost::timer::nanosecond_type(-1);
}
# else
tms tm;
clock_t c = ::times(&tm);
if (c == static_cast<clock_t>(-1)) // error
{
current.system = current.user = boost::timer::nanosecond_type(-1);
}
else
{
current.system = boost::timer::nanosecond_type(tm.tms_stime + tm.tms_cstime);
current.user = boost::timer::nanosecond_type(tm.tms_utime + tm.tms_cutime);
boost::int_least64_t factor;
if ((factor = tick_factor()) != -1)
{
current.user *= factor;
current.system *= factor;
}
else
{
current.user = current.system = boost::timer::nanosecond_type(-1);
}
}
# endif
}
// CAUTION: must be identical to same constant in auto_timers_construction.cpp
const std::string default_fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n");
} // unnamed namespace
namespace boost
{
namespace timer
{
// format ------------------------------------------------------------------------//
BOOST_TIMER_DECL
std::string format(const cpu_times& times, short places, const std::string& fmt)
{
std::stringstream ss;
ss.exceptions(std::ios_base::badbit | std::ios_base::failbit);
show_time(times, ss, fmt, places);
return ss.str();
}
BOOST_TIMER_DECL
std::string format(const cpu_times& times, short places)
{
return format(times, places, default_fmt);
}
// cpu_timer ---------------------------------------------------------------------//
void cpu_timer::start() BOOST_NOEXCEPT
{
m_is_stopped = false;
get_cpu_times(m_times);
}
void cpu_timer::stop() BOOST_NOEXCEPT
{
if (is_stopped())
return;
m_is_stopped = true;
cpu_times current;
get_cpu_times(current);
m_times.wall = (current.wall - m_times.wall);
m_times.user = (current.user - m_times.user);
m_times.system = (current.system - m_times.system);
}
cpu_times cpu_timer::elapsed() const BOOST_NOEXCEPT
{
if (is_stopped())
return m_times;
cpu_times current;
get_cpu_times(current);
current.wall -= m_times.wall;
current.user -= m_times.user;
current.system -= m_times.system;
return current;
}
void cpu_timer::resume() BOOST_NOEXCEPT
{
if (is_stopped())
{
cpu_times current (m_times);
start();
m_times.wall -= current.wall;
m_times.user -= current.user;
m_times.system -= current.system;
}
}
// auto_cpu_timer ----------------------------------------------------------------//
auto_cpu_timer::auto_cpu_timer(std::ostream& os, short places) // #5
: m_places(places), m_os(&os), m_format(default_fmt)
{
start();
}
void auto_cpu_timer::report()
{
show_time(elapsed(), ostream(), format_string(), places());
}
auto_cpu_timer::~auto_cpu_timer()
{
if (!is_stopped())
{
stop(); // the sooner we stop(), the better
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
report();
#ifndef BOOST_NO_EXCEPTIONS
}
catch (...) // eat any exceptions
{
}
#endif
}
}
} // namespace timer
} // namespace boost

View File

@@ -0,0 +1,11 @@
# Copyright 2018, 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(HAVE_BOOST_TEST)
boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::timer Boost::core Boost::detail)
endif()

View File

@@ -0,0 +1,36 @@
# Boost Timer Library test Jamfile
# Copyright Beman Dawes 2003, 2006, 2011
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
# See library home page at http://www.boost.org/libs/timer
import testing ;
path-constant parent : .. ; # so that inspect will start in boost-root/libs/timer
# when run from another directory, such as boost-root/status
project
: requirements
<library>/boost/timer//boost_timer
;
run ../example/auto_cpu_timer_example.cpp : : : <test-info>always_show_run_output ;
run cpu_timer_info.cpp : : : <test-info>always_show_run_output ;
run cpu_timer_test.cpp
: : : <test-info>always_show_run_output ;
run ../example/timex.cpp : echo "Hello, world" : : <test-info>always_show_run_output ;
compile original_timer_test.cpp ;
run chrono_conflict_test.cpp /boost/chrono//boost_chrono : : : <link>static ;
run progress_display_test.cpp ;
run /boost/tools/inspect//inspect/<variant>release : $(parent) -text -brief : : <test-info>always_show_run_output : inspect ;
explicit inspect ;

View File

@@ -0,0 +1,16 @@
// Copyright 2017 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// Check that using Chrono and Timer in the same program does
// not cause link errors.
#include <boost/chrono.hpp>
#include <boost/timer/timer.hpp>
int main()
{
boost::chrono::steady_clock::now();
boost::timer::cpu_timer cpt;
}

View File

@@ -0,0 +1,15 @@
# Copyright 2018-2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.20)
project(cmake_install_test LANGUAGES CXX)
find_package(boost_timer REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main Boost::timer)
enable_testing()
add_test(main main)

View File

@@ -0,0 +1,11 @@
// Copyright 2019 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/timer/timer.hpp>
int main()
{
boost::timer::cpu_timer timer;
timer.stop();
}

View File

@@ -0,0 +1,49 @@
# Copyright 2018-2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.20)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/timer)
set(deps
# Primary dependencies
chrono
config
core
io
predef
system
throw_exception
# Secondary dependencies
assert
integer
move
mpl
ratio
static_assert
type_traits
typeof
utility
winapi
variant2
preprocessor
rational
mp11
)
foreach(dep IN LISTS deps)
add_subdirectory(../../../${dep} boostorg/${dep})
endforeach()
add_executable(main main.cpp)
target_link_libraries(main Boost::timer Boost::core)
enable_testing()
add_test(main main)

View File

@@ -0,0 +1,11 @@
// Copyright 2019 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/timer/timer.hpp>
int main()
{
boost::timer::cpu_timer timer;
timer.stop();
}

View File

@@ -0,0 +1,75 @@
// boost cpu_timer_info.cpp ----------------------------------------------------------//
// Copyright Beman Dawes 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/timer for documentation.
#include <boost/timer/timer.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <cstdlib> // for atol()
#include <iostream>
#include <locale>
using boost::timer::nanosecond_type;
using boost::timer::cpu_times;
using boost::timer::cpu_timer;
using boost::timer::auto_cpu_timer;
using std::cout; using std::endl;
int cpp_main( int argc, char * argv[] )
{
cout << '\n';
cout << "For cpu_times.wall, the underlying clock "
<< (boost::chrono::high_resolution_clock::is_steady
? "is steady. "
: "is not steady. "
)
<< "Steady clocks are defined by C++11 as clocks for which values "
"of time_point never decrease as physical time advances and for "
"which values of time_point advance at a steady rate relative to "
"real time. That is, the clock may not be adjusted.\n\n";
cpu_times start_time;
start_time.clear();
cpu_times current_time;
{
cpu_timer cpu;
cout << "measure boost::timer::cpu_timer resolution for user time..."
<< endl;
for (int i = 0; i < 3; ++i)
{
cpu.start();
start_time = cpu.elapsed();
current_time.user = start_time.user;
while (current_time.user == start_time.user)
{
current_time = cpu.elapsed();
}
cout << current_time.user - start_time.user << "ns\n";
}
}
{
cpu_timer cpu;
cout << "measure boost::timer::cpu_timer resolution for wall-clock time..."
<< endl;
for (int i = 0; i < 100; ++i)
{
cpu.start();
start_time.wall = cpu.elapsed().wall;
current_time.wall = start_time.wall;
while (current_time.wall == start_time.wall)
{
current_time.wall = cpu.elapsed().wall;
}
cout << current_time.wall - start_time.wall << "ns ";
}
}
return 0;
}

View File

@@ -0,0 +1,227 @@
// boost timer_test.cpp --------------------------------------------------------------//
// Copyright Beman Dawes 2006, 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/timer for documentation.
#include <boost/timer/timer.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cstdlib> // for atol()
#include <iostream>
#include <string>
#include <ctime>
using std::string;
using std::cout;
using std::endl;
using boost::timer::default_places;
using boost::timer::nanosecond_type;
using boost::timer::cpu_times;
using boost::timer::format;
using boost::timer::cpu_timer;
using boost::timer::auto_cpu_timer;
namespace
{
void unit_test()
{
cout << "unit test..." << endl;
string default_format(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n");
// each constructor
auto_cpu_timer t1;
BOOST_TEST(!t1.is_stopped());
// the following, and similar below, are giving false failures on MinGW/gcc
// so comment them out for now
//BOOST_TEST(&t1.ostream() == &cout);
BOOST_TEST_EQ(t1.places(), default_places);
BOOST_TEST_EQ(t1.format_string(), default_format);
t1.stop();
BOOST_TEST(t1.is_stopped());
auto_cpu_timer t1a(t1);
BOOST_TEST(t1a.is_stopped());
BOOST_TEST_EQ(t1a.elapsed().wall, t1.elapsed().wall);
BOOST_TEST_EQ(t1a.elapsed().user, t1.elapsed().user);
BOOST_TEST_EQ(t1a.elapsed().system, t1.elapsed().system);
//BOOST_TEST(&t1a.ostream() == &cout);
BOOST_TEST_EQ(t1a.places(), default_places);
BOOST_TEST_EQ(t1a.format_string(), default_format);
auto_cpu_timer t1b;
BOOST_TEST(!t1b.is_stopped());
t1b = t1;
BOOST_TEST(t1b.is_stopped());
BOOST_TEST_EQ(t1b.elapsed().wall, t1.elapsed().wall);
BOOST_TEST_EQ(t1b.elapsed().user, t1.elapsed().user);
BOOST_TEST_EQ(t1b.elapsed().system, t1.elapsed().system);
//BOOST_TEST(&t1b.ostream() == &cout);
BOOST_TEST_EQ(t1b.places(), default_places);
BOOST_TEST_EQ(t1b.format_string(), default_format);
auto_cpu_timer t2(1);
BOOST_TEST(!t2.is_stopped());
//BOOST_TEST(&t2.ostream() == &cout);
BOOST_TEST_EQ(t2.places(), 1);
BOOST_TEST_EQ(t2.format_string(), default_format);
auto_cpu_timer t3("foo");
BOOST_TEST(!t3.is_stopped());
//BOOST_TEST(&t3.ostream() == &cout);
BOOST_TEST_EQ(t3.places(), default_places);
BOOST_TEST_EQ(t3.format_string(), string("foo"));
auto_cpu_timer t4(1, "foo");
BOOST_TEST(!t4.is_stopped());
//BOOST_TEST(&t4.ostream() == &cout);
BOOST_TEST_EQ(t4.places(), 1);
BOOST_TEST_EQ(t4.format_string(), string("foo"));
auto_cpu_timer t5(std::cerr);
BOOST_TEST(!t5.is_stopped());
BOOST_TEST(&t5.ostream() == &std::cerr);
BOOST_TEST_EQ(t5.places(), default_places);
BOOST_TEST_EQ(t5.format_string(), default_format);
auto_cpu_timer t6(std::cerr, 1);
BOOST_TEST(!t6.is_stopped());
BOOST_TEST(&t6.ostream() == &std::cerr);
BOOST_TEST_EQ(t6.places(), 1);
BOOST_TEST_EQ(t6.format_string(), default_format);
auto_cpu_timer t7(std::cerr, "foo");
BOOST_TEST(!t7.is_stopped());
BOOST_TEST(&t7.ostream() == &std::cerr);
BOOST_TEST_EQ(t7.places(), default_places);
BOOST_TEST_EQ(t7.format_string(), string("foo"));
auto_cpu_timer t8(std::cerr, 1, "foo");
BOOST_TEST(!t8.is_stopped());
BOOST_TEST(&t8.ostream() == &std::cerr);
BOOST_TEST_EQ(t8.places(), 1);
BOOST_TEST_EQ(t8.format_string(), string("foo"));
t1.stop();
t1a.stop();
t1b.stop();
t2.stop();
t3.stop();
t4.stop();
t5.stop();
t6.stop();
t7.stop();
t8.stop();
cout << " unit test complete" << endl;
}
void format_test()
{
cout << "format test..." << endl;
cpu_times times;
times.wall = 5123456789LL;
times.user = 2123456789LL;
times.system = 1234567890LL;
cout << " times.wall is " << times.wall << '\n';
cout << " times.user is " << times.user << '\n';
cout << " times.system is " << times.system << '\n';
cout << " user+system is " << times.user + times.system << '\n';
cout << " format(times, 9) output: " << format(times, 9);
BOOST_TEST_EQ(format(times, 9),
string(" 5.123456789s wall, 2.123456789s user + 1.234567890s system = 3.358024679s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 8),
string(" 5.12345679s wall, 2.12345679s user + 1.23456789s system = 3.35802468s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 7),
string(" 5.1234568s wall, 2.1234568s user + 1.2345679s system = 3.3580247s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 6),
string(" 5.123457s wall, 2.123457s user + 1.234568s system = 3.358025s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 5),
string(" 5.12346s wall, 2.12346s user + 1.23457s system = 3.35802s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 4),
string(" 5.1235s wall, 2.1235s user + 1.2346s system = 3.3580s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 3),
string(" 5.123s wall, 2.123s user + 1.235s system = 3.358s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 2),
string(" 5.12s wall, 2.12s user + 1.23s system = 3.36s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 1),
string(" 5.1s wall, 2.1s user + 1.2s system = 3.4s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 0),
string(" 5s wall, 2s user + 1s system = 3s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 10),
string(" 5.123456789s wall, 2.123456789s user + 1.234567890s system = 3.358024679s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, -1),
string(" 5.123457s wall, 2.123457s user + 1.234568s system = 3.358025s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times),
string(" 5.123457s wall, 2.123457s user + 1.234568s system = 3.358025s CPU (65.5%)\n"));
BOOST_TEST_EQ(format(times, 5, " %w, %u, %s, %t, %%p%"),
string(" 5.12346, 2.12346, 1.23457, 3.35802, %65.5%"));
BOOST_TEST_EQ(format(times, 5, "boo"), string("boo"));
cout << " format test complete" << endl;
}
void std_c_consistency_test()
{
cout << "C library consistency test..." << endl;
// This test is designed to account for C timer resolution and for the possibility
// that another active process may take up a lot of time.
cpu_timer t; // calls start(), so ensures any cpu_timer dll loaded
std::time(0); // ensure any system dll's loaded
std::time_t stop_time, start_time = std::time(0);
// wait until the time() clock ticks
while (std::time(0) == start_time) {}
// start both timers
start_time = std::time(0);
t.start();
// wait until the time() clock ticks again
while (std::time(0) == start_time) {}
// stop both timers
stop_time = std::time(0);
t.stop();
cout << " std::time() elapsed is " << (stop_time - start_time) * 1.0L << " seconds\n";
cout << " cpu_timer wall elapsed is " << t.elapsed().wall / 1000000000.0L << " seconds\n";
cout << " The two clocks whose elapsed time is compared by this test are started\n"
" and stopped one right after the other. If the operating system suspends\n"
" the process in the interim, the test may fail. Thus no single failure\n"
" of this test is meaningful.\n";
// These tests allow lots of fuzz to reduce false positives
BOOST_TEST(t.elapsed().wall / 1000000000.0L > (stop_time - start_time) * 0.75L);
BOOST_TEST(t.elapsed().wall / 1000000000.0L < (stop_time - start_time) * 1.25L);
cout << " C library consistency test complete" << endl;
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
int cpp_main(int, char *[])
{
cout << "---------- timer_test ----------\n";
unit_test();
format_test();
std_c_consistency_test();
return ::boost::report_errors();
}

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C88697D9-587C-4649-AA39-8819A96A2A12}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>chrono_dll</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CHRONO_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CHRONO_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\chrono\src\chrono.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\system_dll\system_dll.vcxproj">
<Project>{443dd1e8-4d52-4323-8280-a2320df7ef6d}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>../../../../..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level4</WarningLevel>
</ClCompile>
<PostBuildEvent>
<Command>"$(TargetDir)\$(TargetName).exe"</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Executing test $(TargetName).exe...</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{955C9C33-5364-4F02-9D59-65657E8DFBA9}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>cpu_timer_test</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\cpu_timer_test.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\chrono_dll\chrono_dll.vcxproj">
<Project>{c88697d9-587c-4649-aa39-8819a96a2a12}</Project>
</ProjectReference>
<ProjectReference Include="..\system_dll\system_dll.vcxproj">
<Project>{443dd1e8-4d52-4323-8280-a2320df7ef6d}</Project>
</ProjectReference>
<ProjectReference Include="..\timer_dll\timer_dll.vcxproj">
<Project>{8a6cf2a1-c5f7-4119-b510-88b98197bcb2}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{443DD1E8-4D52-4323-8280-A2320DF7EF6D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>system_dll</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;SYSTEM_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SYSTEM_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\system\src\error_code.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,50 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "timer_dll", "timer_dll\timer_dll.vcxproj", "{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}"
ProjectSection(ProjectDependencies) = postProject
{C88697D9-587C-4649-AA39-8819A96A2A12} = {C88697D9-587C-4649-AA39-8819A96A2A12}
{443DD1E8-4D52-4323-8280-A2320DF7EF6D} = {443DD1E8-4D52-4323-8280-A2320DF7EF6D}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chrono_dll", "chrono_dll\chrono_dll.vcxproj", "{C88697D9-587C-4649-AA39-8819A96A2A12}"
ProjectSection(ProjectDependencies) = postProject
{443DD1E8-4D52-4323-8280-A2320DF7EF6D} = {443DD1E8-4D52-4323-8280-A2320DF7EF6D}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_dll", "system_dll\system_dll.vcxproj", "{443DD1E8-4D52-4323-8280-A2320DF7EF6D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpu_timer_test", "cpu_timer_test\cpu_timer_test.vcxproj", "{955C9C33-5364-4F02-9D59-65657E8DFBA9}"
ProjectSection(ProjectDependencies) = postProject
{8A6CF2A1-C5F7-4119-B510-88B98197BCB2} = {8A6CF2A1-C5F7-4119-B510-88B98197BCB2}
{C88697D9-587C-4649-AA39-8819A96A2A12} = {C88697D9-587C-4649-AA39-8819A96A2A12}
{443DD1E8-4D52-4323-8280-A2320DF7EF6D} = {443DD1E8-4D52-4323-8280-A2320DF7EF6D}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Debug|Win32.ActiveCfg = Debug|Win32
{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Debug|Win32.Build.0 = Debug|Win32
{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Release|Win32.ActiveCfg = Release|Win32
{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Release|Win32.Build.0 = Release|Win32
{C88697D9-587C-4649-AA39-8819A96A2A12}.Debug|Win32.ActiveCfg = Debug|Win32
{C88697D9-587C-4649-AA39-8819A96A2A12}.Debug|Win32.Build.0 = Debug|Win32
{C88697D9-587C-4649-AA39-8819A96A2A12}.Release|Win32.ActiveCfg = Release|Win32
{C88697D9-587C-4649-AA39-8819A96A2A12}.Release|Win32.Build.0 = Release|Win32
{443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Debug|Win32.ActiveCfg = Debug|Win32
{443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Debug|Win32.Build.0 = Debug|Win32
{443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Release|Win32.ActiveCfg = Release|Win32
{443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Release|Win32.Build.0 = Release|Win32
{955C9C33-5364-4F02-9D59-65657E8DFBA9}.Debug|Win32.ActiveCfg = Debug|Win32
{955C9C33-5364-4F02-9D59-65657E8DFBA9}.Debug|Win32.Build.0 = Debug|Win32
{955C9C33-5364-4F02-9D59-65657E8DFBA9}.Release|Win32.ActiveCfg = Release|Win32
{955C9C33-5364-4F02-9D59-65657E8DFBA9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>timer_dll</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;TIMER_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TIMER_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\auto_timers_construction.cpp" />
<ClCompile Include="..\..\..\src\cpu_timer.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\chrono_dll\chrono_dll.vcxproj">
<Project>{c88697d9-587c-4649-aa39-8819a96a2a12}</Project>
</ProjectReference>
<ProjectReference Include="..\system_dll\system_dll.vcxproj">
<Project>{443dd1e8-4d52-4323-8280-a2320df7ef6d}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,89 @@
// timer, job_timer, and progress_display sample program -------------------//
// Copyright Beman Dawes 1998. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/timer for documentation.
// Revision History
// 12 Jan 01 Cut time to 1.0 secs to speed regression tests (Beman Dawes)
// 25 Sep 99 added elapsed_min() and elapsed_max() reporting
// 16 Jul 99 Second beta
// 6 Jul 99 Initial boost version
#include <boost/progress.hpp>
#include <iostream>
#include <climits>
using boost::timer;
using boost::progress_timer;
using boost::progress_display;
using std::cout;
using std::endl;
int main() {
timer t0; // used only for elapsed_max() and elapsed_min()
cout << "timer::elapsed_min() reports " << t0.elapsed_min() << " seconds\n";
cout << "timer::elapsed_max() reports " << t0.elapsed_max()
<< " seconds, which is " << t0.elapsed_max()/3600.0 << " hours\n";
cout << "\nverify progress_display(0) doesn't divide by zero" << endl;
progress_display zero( 0 ); // verify 0 doesn't divide by zero
++zero;
long loops;
timer loop_timer;
const double time = 1.0;
cout << "\ndetermine " << time << " second iteration count" << endl;
for ( loops = 0; loops < LONG_MAX
&& loop_timer.elapsed() < time; ++loops ) {}
cout << loops << " iterations"<< endl;
long i;
bool time_waster; // defeat [some] optimizers by storing result here
progress_timer pt;
timer t1;
timer t4;
timer t5;
cout << "\nburn about " << time << " seconds" << endl;
progress_display pd( loops );
for ( i = loops; i--; )
{ time_waster = loop_timer.elapsed() < time; ++pd; }
timer t2( t1 );
timer t3;
t4 = t3;
t5.restart();
cout << "\nburn about " << time << " seconds again" << endl;
pd.restart( loops );
for ( i = loops; i--; )
{ time_waster = loop_timer.elapsed() < time; ++pd; }
if ( time_waster ) cout << ' '; // using time_waster quiets compiler warnings
progress_display pd2( 50, cout, "\nLead string 1 ", "Lead string 2 ", "Lead string 3 " );
for ( ; pd2.count() < 50; ++pd2 ) {}
cout << "\nt1 elapsed: " << t1.elapsed() << '\n';
cout << "t2 elapsed: " << t2.elapsed() << '\n';
cout << "t3 elapsed: " << t3.elapsed() << '\n';
cout << "t4 elapsed: " << t4.elapsed() << '\n';
cout << "t5 elapsed: " << t5.elapsed() << '\n';
cout << "t1 and t2 should report the same times (very approximately "
<< 2*time << " seconds).\n";
cout << "t3, t4 and t5 should report about the same times,\n";
cout << "and these should be about half the t1 and t2 times.\n";
cout << "The following elapsed time should be slightly greater than t1."
<< endl;
return 0;
} // main

View File

@@ -0,0 +1,37 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/timer/progress_display.hpp>
#include <boost/core/lightweight_test.hpp>
#include <sstream>
#include <cstddef>
int main()
{
int n = 17;
std::ostringstream os;
boost::timer::progress_display pd( n, os, "L1:", "L2:", "L3:" );
BOOST_TEST_EQ( os.str(), std::string(
"L1:0% 10 20 30 40 50 60 70 80 90 100%\n"
"L2:|----|----|----|----|----|----|----|----|----|----|\n"
"L3:" ) );
for( int i = 0; i < n; ++i )
{
std::size_t m1 = os.str().size();
++pd;
std::size_t m2 = os.str().size();
BOOST_TEST_LE( m1, m2 );
}
BOOST_TEST_EQ( os.str(), std::string(
"L1:0% 10 20 30 40 50 60 70 80 90 100%\n"
"L2:|----|----|----|----|----|----|----|----|----|----|\n"
"L3:***************************************************\n" ) );
return boost::report_errors();
}