├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .travis.yml ├── CMakeLists.txt ├── appveyor.yml ├── build.jam ├── build └── Jamfile.v2 ├── doc ├── cpu_timers.html ├── index.html └── original_timer.html ├── example ├── auto_cpu_timer_example.cpp └── timex.cpp ├── include └── boost │ ├── progress.hpp │ ├── timer.hpp │ └── timer │ ├── config.hpp │ ├── progress_display.hpp │ └── timer.hpp ├── index.html ├── meta └── libraries.json ├── src ├── auto_timers_construction.cpp └── cpu_timer.cpp └── test ├── CMakeLists.txt ├── Jamfile.v2 ├── chrono_conflict_test.cpp ├── cmake_install_test ├── CMakeLists.txt └── main.cpp ├── cmake_subdir_test ├── CMakeLists.txt └── main.cpp ├── cpu_timer_info.cpp ├── cpu_timer_test.cpp ├── msvc10 ├── chrono_dll │ └── chrono_dll.vcxproj ├── common.props ├── cpu_timer_test │ └── cpu_timer_test.vcxproj ├── system_dll │ └── system_dll.vcxproj ├── timer.sln └── timer_dll │ └── timer_dll.vcxproj ├── original_timer_test.cpp └── progress_display_test.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | - develop 9 | - feature/** 10 | 11 | env: 12 | UBSAN_OPTIONS: print_stacktrace=1 13 | 14 | jobs: 15 | posix: 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | include: 20 | - toolset: gcc-4.8 21 | cxxstd: "11" 22 | os: ubuntu-latest 23 | container: ubuntu:18.04 24 | install: g++-4.8 25 | - toolset: gcc-5 26 | cxxstd: "11,14,1z" 27 | os: ubuntu-latest 28 | container: ubuntu:18.04 29 | install: g++-5 30 | - toolset: gcc-6 31 | cxxstd: "11,14,1z" 32 | os: ubuntu-latest 33 | container: ubuntu:18.04 34 | install: g++-6 35 | - toolset: gcc-7 36 | cxxstd: "11,14,17" 37 | os: ubuntu-20.04 38 | install: g++-7 39 | - toolset: gcc-8 40 | cxxstd: "11,14,17,2a" 41 | os: ubuntu-20.04 42 | install: g++-8 43 | - toolset: gcc-9 44 | cxxstd: "11,14,17,2a" 45 | os: ubuntu-20.04 46 | - toolset: gcc-10 47 | cxxstd: "11,14,17,2a" 48 | os: ubuntu-20.04 49 | install: g++-10 50 | - toolset: gcc-11 51 | cxxstd: "11,14,17,2a" 52 | os: ubuntu-22.04 53 | - toolset: gcc-12 54 | cxxstd: "11,14,17,20,2b" 55 | os: ubuntu-22.04 56 | install: g++-12 57 | - toolset: gcc-13 58 | cxxstd: "11,14,17,20,2b" 59 | container: ubuntu:24.04 60 | os: ubuntu-latest 61 | install: g++-13 62 | - toolset: gcc-14 63 | cxxstd: "11,14,17,20,2b" 64 | container: ubuntu:24.04 65 | os: ubuntu-latest 66 | install: g++-14 67 | - toolset: clang 68 | compiler: clang++-3.9 69 | cxxstd: "11,14" 70 | os: ubuntu-latest 71 | container: ubuntu:18.04 72 | install: clang-3.9 73 | - toolset: clang 74 | compiler: clang++-4.0 75 | cxxstd: "11,14" 76 | os: ubuntu-latest 77 | container: ubuntu:18.04 78 | install: clang-4.0 79 | - toolset: clang 80 | compiler: clang++-5.0 81 | cxxstd: "11,14,1z" 82 | os: ubuntu-latest 83 | container: ubuntu:18.04 84 | install: clang-5.0 85 | - toolset: clang 86 | compiler: clang++-6.0 87 | cxxstd: "11,14,17" 88 | os: ubuntu-20.04 89 | install: clang-6.0 90 | - toolset: clang 91 | compiler: clang++-7 92 | cxxstd: "11,14,17" 93 | os: ubuntu-20.04 94 | install: clang-7 95 | - toolset: clang 96 | compiler: clang++-8 97 | cxxstd: "11,14,17,2a" 98 | os: ubuntu-20.04 99 | install: clang-8 100 | - toolset: clang 101 | compiler: clang++-9 102 | cxxstd: "11,14,17,2a" 103 | os: ubuntu-20.04 104 | install: clang-9 105 | - toolset: clang 106 | compiler: clang++-10 107 | cxxstd: "11,14,17,2a" 108 | os: ubuntu-20.04 109 | install: clang-10 110 | - toolset: clang 111 | compiler: clang++-11 112 | cxxstd: "11,14,17,2a" 113 | os: ubuntu-20.04 114 | install: clang-11 115 | - toolset: clang 116 | compiler: clang++-12 117 | cxxstd: "11,14,17,2a" 118 | os: ubuntu-20.04 119 | install: clang-12 120 | - toolset: clang 121 | compiler: clang++-13 122 | cxxstd: "11,14,17,20,2b" 123 | container: ubuntu:22.04 124 | os: ubuntu-latest 125 | install: clang-13 126 | - toolset: clang 127 | compiler: clang++-14 128 | cxxstd: "11,14,17,20,2b" 129 | container: ubuntu:22.04 130 | os: ubuntu-latest 131 | install: clang-14 132 | - toolset: clang 133 | compiler: clang++-15 134 | cxxstd: "11,14,17,20,2b" 135 | container: ubuntu:22.04 136 | os: ubuntu-latest 137 | install: clang-15 138 | - toolset: clang 139 | compiler: clang++-16 140 | cxxstd: "11,14,17,20,2b" 141 | container: ubuntu:24.04 142 | os: ubuntu-latest 143 | install: clang-16 144 | - toolset: clang 145 | compiler: clang++-17 146 | cxxstd: "11,14,17,20,2b" 147 | container: ubuntu:24.04 148 | os: ubuntu-latest 149 | install: clang-17 150 | - toolset: clang 151 | compiler: clang++-18 152 | cxxstd: "11,14,17,20,2b" 153 | container: ubuntu:24.04 154 | os: ubuntu-latest 155 | install: clang-18 156 | - toolset: clang 157 | compiler: clang++-19 158 | cxxstd: "11,14,17,20,2b" 159 | container: ubuntu:24.10 160 | os: ubuntu-latest 161 | install: clang-19 162 | - toolset: clang 163 | cxxstd: "11,14,17,20,2b" 164 | os: macos-13 165 | - toolset: clang 166 | cxxstd: "11,14,17,20,2b" 167 | os: macos-14 168 | - toolset: clang 169 | cxxstd: "11,14,17,20,2b" 170 | os: macos-15 171 | 172 | runs-on: ${{matrix.os}} 173 | 174 | container: 175 | image: ${{matrix.container}} 176 | volumes: 177 | - /node20217:/node20217:rw,rshared 178 | - ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }} 179 | 180 | defaults: 181 | run: 182 | shell: bash 183 | 184 | steps: 185 | - name: Setup container environment 186 | if: matrix.container 187 | run: | 188 | apt-get update 189 | apt-get -y install sudo python3 git g++ curl xz-utils 190 | 191 | - name: Install nodejs20glibc2.17 192 | if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }} 193 | run: | 194 | curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz 195 | tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217 196 | ldd /__e/node20/bin/node 197 | 198 | - uses: actions/checkout@v4 199 | 200 | - name: Install packages 201 | if: matrix.install 202 | run: | 203 | sudo apt-get update 204 | sudo apt-get -y install ${{matrix.install}} 205 | 206 | - name: Setup Boost 207 | run: | 208 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 209 | LIBRARY=${GITHUB_REPOSITORY#*/} 210 | echo LIBRARY: $LIBRARY 211 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 212 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 213 | echo GITHUB_REF: $GITHUB_REF 214 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 215 | REF=${REF#refs/heads/} 216 | echo REF: $REF 217 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 218 | echo BOOST_BRANCH: $BOOST_BRANCH 219 | cd .. 220 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 221 | cd boost-root 222 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 223 | git submodule update --init tools/boostdep 224 | python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 225 | ./bootstrap.sh 226 | ./b2 -d0 headers 227 | 228 | - name: Create user-config.jam 229 | if: matrix.compiler 230 | run: | 231 | echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam 232 | 233 | - name: Run tests 234 | run: | 235 | cd ../boost-root 236 | ./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release 237 | 238 | windows: 239 | strategy: 240 | fail-fast: false 241 | matrix: 242 | include: 243 | - toolset: msvc-14.0 244 | cxxstd: "14,latest" 245 | addrmd: 32,64 246 | os: windows-2019 247 | - toolset: msvc-14.2 248 | cxxstd: "14,17,20,latest" 249 | addrmd: 32,64 250 | os: windows-2019 251 | - toolset: msvc-14.3 252 | cxxstd: "14,17,20,latest" 253 | addrmd: 32,64 254 | os: windows-2022 255 | - toolset: clang-win 256 | cxxstd: "14,17,latest" 257 | addrmd: 32,64 258 | os: windows-2022 259 | - toolset: gcc 260 | cxxstd: "11,14,17,2a" 261 | addrmd: 64 262 | os: windows-2019 263 | 264 | runs-on: ${{matrix.os}} 265 | 266 | steps: 267 | - uses: actions/checkout@v4 268 | 269 | - name: Setup Boost 270 | shell: cmd 271 | run: | 272 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 273 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 274 | echo LIBRARY: %LIBRARY% 275 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 276 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 277 | echo GITHUB_REF: %GITHUB_REF% 278 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 279 | set BOOST_BRANCH=develop 280 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 281 | echo BOOST_BRANCH: %BOOST_BRANCH% 282 | cd .. 283 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 284 | cd boost-root 285 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 286 | git submodule update --init tools/boostdep 287 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 288 | cmd /c bootstrap 289 | b2 -d0 headers 290 | 291 | - name: Run tests 292 | shell: cmd 293 | run: | 294 | cd ../boost-root 295 | b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker 296 | 297 | posix-cmake-subdir: 298 | strategy: 299 | fail-fast: false 300 | matrix: 301 | os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-13, macos-14, macos-15 ] 302 | shared: [ OFF, ON ] 303 | 304 | runs-on: ${{matrix.os}} 305 | 306 | steps: 307 | - uses: actions/checkout@v4 308 | 309 | - name: Install packages 310 | if: matrix.install 311 | run: sudo apt-get -y install ${{matrix.install}} 312 | 313 | - name: Setup Boost 314 | run: | 315 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 316 | LIBRARY=${GITHUB_REPOSITORY#*/} 317 | echo LIBRARY: $LIBRARY 318 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 319 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 320 | echo GITHUB_REF: $GITHUB_REF 321 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 322 | REF=${REF#refs/heads/} 323 | echo REF: $REF 324 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 325 | echo BOOST_BRANCH: $BOOST_BRANCH 326 | cd .. 327 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 328 | cd boost-root 329 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 330 | git submodule update --init tools/boostdep 331 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 332 | 333 | - name: Use library with add_subdirectory 334 | run: | 335 | cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test 336 | mkdir __build__ && cd __build__ 337 | cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} .. 338 | cmake --build . 339 | ctest --output-on-failure --no-tests=error 340 | 341 | posix-cmake-install: 342 | strategy: 343 | fail-fast: false 344 | matrix: 345 | os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-13, macos-14, macos-15 ] 346 | shared: [ OFF, ON ] 347 | 348 | runs-on: ${{matrix.os}} 349 | 350 | steps: 351 | - uses: actions/checkout@v4 352 | 353 | - name: Install packages 354 | if: matrix.install 355 | run: sudo apt-get -y install ${{matrix.install}} 356 | 357 | - name: Setup Boost 358 | run: | 359 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 360 | LIBRARY=${GITHUB_REPOSITORY#*/} 361 | echo LIBRARY: $LIBRARY 362 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 363 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 364 | echo GITHUB_REF: $GITHUB_REF 365 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 366 | REF=${REF#refs/heads/} 367 | echo REF: $REF 368 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 369 | echo BOOST_BRANCH: $BOOST_BRANCH 370 | cd .. 371 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 372 | cd boost-root 373 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 374 | git submodule update --init tools/boostdep 375 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 376 | 377 | - name: Configure 378 | run: | 379 | cd ../boost-root 380 | mkdir __build__ && cd __build__ 381 | cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=${{matrix.shared}} .. 382 | 383 | - name: Build 384 | run: | 385 | cd ../boost-root/__build__ 386 | cmake --build . 387 | 388 | - name: Install 389 | run: | 390 | cd ../boost-root/__build__ 391 | cmake --build . --target install 392 | 393 | - name: Use the installed library 394 | run: | 395 | cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__ 396 | cmake -DCMAKE_INSTALL_PREFIX=~/.local .. 397 | cmake --build . 398 | export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH 399 | ctest --output-on-failure --no-tests=error 400 | 401 | posix-cmake-test: 402 | strategy: 403 | fail-fast: false 404 | matrix: 405 | os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-13, macos-14, macos-15 ] 406 | shared: [ OFF, ON ] 407 | 408 | runs-on: ${{matrix.os}} 409 | 410 | steps: 411 | - uses: actions/checkout@v4 412 | 413 | - name: Install packages 414 | if: matrix.install 415 | run: sudo apt-get -y install ${{matrix.install}} 416 | 417 | - name: Setup Boost 418 | run: | 419 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 420 | LIBRARY=${GITHUB_REPOSITORY#*/} 421 | echo LIBRARY: $LIBRARY 422 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 423 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 424 | echo GITHUB_REF: $GITHUB_REF 425 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 426 | REF=${REF#refs/heads/} 427 | echo REF: $REF 428 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 429 | echo BOOST_BRANCH: $BOOST_BRANCH 430 | cd .. 431 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 432 | cd boost-root 433 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 434 | git submodule update --init tools/boostdep 435 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 436 | 437 | - name: Configure 438 | run: | 439 | cd ../boost-root 440 | mkdir __build__ && cd __build__ 441 | cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} .. 442 | 443 | - name: Build tests 444 | run: | 445 | cd ../boost-root/__build__ 446 | cmake --build . --target tests 447 | 448 | - name: Run tests 449 | run: | 450 | cd ../boost-root/__build__ 451 | ctest --output-on-failure --no-tests=error 452 | 453 | windows-cmake-subdir: 454 | strategy: 455 | fail-fast: false 456 | matrix: 457 | os: [ windows-2019, windows-2022 ] 458 | shared: [ OFF, ON ] 459 | 460 | runs-on: ${{matrix.os}} 461 | 462 | steps: 463 | - uses: actions/checkout@v4 464 | 465 | - name: Setup Boost 466 | shell: cmd 467 | run: | 468 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 469 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 470 | echo LIBRARY: %LIBRARY% 471 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 472 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 473 | echo GITHUB_REF: %GITHUB_REF% 474 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 475 | set BOOST_BRANCH=develop 476 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 477 | echo BOOST_BRANCH: %BOOST_BRANCH% 478 | cd .. 479 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 480 | cd boost-root 481 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 482 | git submodule update --init tools/boostdep 483 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 484 | 485 | - name: Use library with add_subdirectory (Debug) 486 | shell: cmd 487 | run: | 488 | cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test 489 | mkdir __build__ && cd __build__ 490 | cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} .. 491 | cmake --build . --config Debug 492 | ctest --output-on-failure --no-tests=error -C Debug 493 | 494 | - name: Use library with add_subdirectory (Release) 495 | shell: cmd 496 | run: | 497 | cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__ 498 | cmake --build . --config Release 499 | ctest --output-on-failure --no-tests=error -C Release 500 | 501 | windows-cmake-install: 502 | strategy: 503 | fail-fast: false 504 | matrix: 505 | os: [ windows-2019, windows-2022 ] 506 | shared: [ OFF, ON ] 507 | 508 | runs-on: ${{matrix.os}} 509 | 510 | steps: 511 | - uses: actions/checkout@v4 512 | 513 | - name: Setup Boost 514 | shell: cmd 515 | run: | 516 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 517 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 518 | echo LIBRARY: %LIBRARY% 519 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 520 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 521 | echo GITHUB_REF: %GITHUB_REF% 522 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 523 | set BOOST_BRANCH=develop 524 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 525 | echo BOOST_BRANCH: %BOOST_BRANCH% 526 | cd .. 527 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 528 | cd boost-root 529 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 530 | git submodule update --init tools/boostdep 531 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 532 | 533 | - name: Configure 534 | shell: cmd 535 | run: | 536 | cd ../boost-root 537 | mkdir __build__ && cd __build__ 538 | cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix -DBUILD_SHARED_LIBS=${{matrix.shared}} .. 539 | 540 | - name: Install (Debug) 541 | shell: cmd 542 | run: | 543 | cd ../boost-root/__build__ 544 | cmake --build . --target install --config Debug 545 | 546 | - name: Install (Release) 547 | shell: cmd 548 | run: | 549 | cd ../boost-root/__build__ 550 | cmake --build . --target install --config Release 551 | 552 | - name: Use the installed library (Debug) 553 | shell: cmd 554 | run: | 555 | cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__ 556 | cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. 557 | cmake --build . --config Debug 558 | PATH C:\cmake-prefix\bin;%PATH% 559 | ctest --output-on-failure --no-tests=error -C Debug 560 | 561 | - name: Use the installed library (Release) 562 | shell: cmd 563 | run: | 564 | cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__ 565 | cmake --build . --config Release 566 | PATH C:\cmake-prefix\bin;%PATH% 567 | ctest --output-on-failure --no-tests=error -C Release 568 | 569 | windows-cmake-test: 570 | strategy: 571 | fail-fast: false 572 | matrix: 573 | os: [ windows-2019, windows-2022 ] 574 | shared: [ OFF, ON ] 575 | 576 | runs-on: ${{matrix.os}} 577 | 578 | steps: 579 | - uses: actions/checkout@v4 580 | 581 | - name: Setup Boost 582 | shell: cmd 583 | run: | 584 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 585 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 586 | echo LIBRARY: %LIBRARY% 587 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 588 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 589 | echo GITHUB_REF: %GITHUB_REF% 590 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 591 | set BOOST_BRANCH=develop 592 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 593 | echo BOOST_BRANCH: %BOOST_BRANCH% 594 | cd .. 595 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 596 | cd boost-root 597 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 598 | git submodule update --init tools/boostdep 599 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 600 | 601 | - name: Configure 602 | shell: cmd 603 | run: | 604 | cd ../boost-root 605 | mkdir __build__ && cd __build__ 606 | cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} .. 607 | 608 | - name: Build tests (Debug) 609 | shell: cmd 610 | run: | 611 | cd ../boost-root/__build__ 612 | cmake --build . --target tests --config Debug 613 | 614 | - name: Run tests (Debug) 615 | shell: cmd 616 | run: | 617 | cd ../boost-root/__build__ 618 | ctest --output-on-failure --no-tests=error -C Debug 619 | 620 | - name: Build tests (Release) 621 | shell: cmd 622 | run: | 623 | cd ../boost-root/__build__ 624 | cmake --build . --target tests --config Release 625 | 626 | - name: Run tests (Release) 627 | shell: cmd 628 | run: | 629 | cd ../boost-root/__build__ 630 | ctest --output-on-failure --no-tests=error -C Release 631 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016-2018 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | language: cpp 6 | 7 | sudo: false 8 | 9 | branches: 10 | only: 11 | - master 12 | - develop 13 | - /feature\/.*/ 14 | 15 | env: 16 | matrix: 17 | - BOGUS_JOB=true 18 | 19 | matrix: 20 | 21 | exclude: 22 | - env: BOGUS_JOB=true 23 | 24 | include: 25 | - os: linux 26 | compiler: g++ 27 | env: TOOLSET=gcc CXXSTD=03,11 28 | 29 | - os: linux 30 | compiler: g++-4.4 31 | env: TOOLSET=gcc CXXSTD=98,0x 32 | addons: 33 | apt: 34 | packages: 35 | - g++-4.4 36 | sources: 37 | - ubuntu-toolchain-r-test 38 | 39 | - os: linux 40 | compiler: g++-4.6 41 | env: TOOLSET=gcc CXXSTD=03,0x 42 | addons: 43 | apt: 44 | packages: 45 | - g++-4.6 46 | sources: 47 | - ubuntu-toolchain-r-test 48 | 49 | - os: linux 50 | compiler: g++-4.8 51 | env: TOOLSET=gcc CXXSTD=03,11 52 | addons: 53 | apt: 54 | packages: 55 | - g++-4.8 56 | sources: 57 | - ubuntu-toolchain-r-test 58 | 59 | - os: linux 60 | compiler: g++-5 61 | env: TOOLSET=gcc CXXSTD=03,11,14,1z 62 | addons: 63 | apt: 64 | packages: 65 | - g++-5 66 | sources: 67 | - ubuntu-toolchain-r-test 68 | 69 | - os: linux 70 | compiler: g++-6 71 | env: TOOLSET=gcc CXXSTD=03,11,14,1z 72 | addons: 73 | apt: 74 | packages: 75 | - g++-6 76 | sources: 77 | - ubuntu-toolchain-r-test 78 | 79 | - os: linux 80 | compiler: g++-7 81 | env: TOOLSET=gcc CXXSTD=03,11,14,17 82 | addons: 83 | apt: 84 | packages: 85 | - g++-7 86 | sources: 87 | - ubuntu-toolchain-r-test 88 | 89 | - os: linux 90 | compiler: g++-8 91 | env: TOOLSET=gcc CXXSTD=03,11,14,17,2a 92 | addons: 93 | apt: 94 | packages: 95 | - g++-8 96 | sources: 97 | - ubuntu-toolchain-r-test 98 | 99 | - os: linux 100 | compiler: g++-9 101 | env: TOOLSET=gcc CXXSTD=03,11,14,17,2a 102 | addons: 103 | apt: 104 | packages: 105 | - g++-9 106 | sources: 107 | - ubuntu-toolchain-r-test 108 | 109 | - os: linux 110 | compiler: g++-9 111 | env: UBSAN=1 TOOLSET=gcc CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold 112 | addons: 113 | apt: 114 | packages: 115 | - g++-9 116 | sources: 117 | - ubuntu-toolchain-r-test 118 | 119 | - os: linux 120 | compiler: clang++ 121 | env: TOOLSET=clang CXXSTD=03,11,14,1z 122 | 123 | - os: linux 124 | compiler: clang++ 125 | env: UBSAN=1 TOOLSET=clang CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1 126 | 127 | - os: linux 128 | dist: trusty 129 | compiler: clang++-libc++ 130 | env: TOOLSET=clang CXXSTD=03,11,14,1z 131 | addons: 132 | apt: 133 | packages: 134 | - libc++-dev 135 | 136 | - os: linux 137 | dist: trusty 138 | compiler: clang++-libc++ 139 | env: UBSAN=1 TOOLSET=clang CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1 140 | addons: 141 | apt: 142 | packages: 143 | - libc++-dev 144 | 145 | - os: osx 146 | compiler: clang++ 147 | env: TOOLSET=clang CXXSTD=03,11,14,1z 148 | 149 | - os: linux 150 | env: CMAKE=1 151 | script: 152 | - mkdir __build__ && cd __build__ 153 | - cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer .. 154 | - cmake --build . --target tests 155 | - ctest --output-on-failure --no-tests=error 156 | 157 | - os: linux 158 | env: CMAKE=1 BUILD_SHARED_LIBS=ON 159 | script: 160 | - mkdir __build__ && cd __build__ 161 | - cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer -DBUILD_SHARED_LIBS=ON .. 162 | - cmake --build . --target tests 163 | - ctest --output-on-failure --no-tests=error 164 | 165 | install: 166 | - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true 167 | - cd .. 168 | - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root 169 | - cd boost-root 170 | - git submodule update --init tools/boostdep 171 | - git submodule update --init tools/cmake 172 | - cp -r $TRAVIS_BUILD_DIR/* libs/timer 173 | - python tools/boostdep/depinst/depinst.py timer 174 | - ./bootstrap.sh 175 | - ./b2 headers 176 | 177 | script: 178 | - |- 179 | echo "using $TOOLSET : : $TRAVIS_COMPILER ;" > ~/user-config.jam 180 | - ./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} 181 | 182 | notifications: 183 | email: 184 | on_success: always 185 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake timer` 2 | # Copyright 2020, 2021 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.5...3.20) 7 | 8 | project(boost_timer VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_timer 11 | src/auto_timers_construction.cpp 12 | src/cpu_timer.cpp 13 | ) 14 | 15 | add_library(Boost::timer ALIAS boost_timer) 16 | 17 | target_include_directories(boost_timer PUBLIC include) 18 | 19 | target_link_libraries(boost_timer 20 | PUBLIC 21 | Boost::config 22 | PRIVATE 23 | Boost::io 24 | Boost::predef 25 | ) 26 | 27 | target_compile_definitions(boost_timer 28 | PUBLIC BOOST_TIMER_NO_LIB 29 | PRIVATE BOOST_TIMER_SOURCE 30 | ) 31 | 32 | if(BUILD_SHARED_LIBS) 33 | target_compile_definitions(boost_timer PUBLIC BOOST_TIMER_DYN_LINK) 34 | else() 35 | target_compile_definitions(boost_timer PUBLIC BOOST_TIMER_STATIC_LINK) 36 | endif() 37 | 38 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 39 | 40 | add_subdirectory(test) 41 | 42 | endif() 43 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016-2019 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | version: 1.0.{build}-{branch} 6 | 7 | shallow_clone: true 8 | 9 | branches: 10 | only: 11 | - master 12 | - develop 13 | - /feature\/.*/ 14 | 15 | environment: 16 | matrix: 17 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 18 | TOOLSET: msvc-14.0 19 | ADDRMD: 32,64 20 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 21 | TOOLSET: msvc-14.1 22 | CXXSTD: 14,17,latest 23 | ADDRMD: 32,64 24 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 25 | TOOLSET: clang-win 26 | CXXSTD: 14,17,20,latest 27 | ADDRMD: 64 28 | 29 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 30 | ADDPATH: C:\cygwin64\bin; 31 | TOOLSET: gcc 32 | CXXSTD: 11,14,1z 33 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 34 | ADDPATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin; 35 | TOOLSET: gcc 36 | CXXSTD: 11,14,1z 37 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 38 | ADDPATH: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin; 39 | TOOLSET: gcc 40 | CXXSTD: 11,14,1z 41 | 42 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 43 | CMAKE: 1 44 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 45 | CMAKE: 1 46 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 47 | CMAKE: 1 48 | 49 | install: 50 | - set BOOST_BRANCH=develop 51 | - if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master 52 | - cd .. 53 | - git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 54 | - cd boost-root 55 | - git submodule update --init tools/boostdep 56 | - git submodule update --init tools/cmake 57 | - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\timer\ 58 | - python tools/boostdep/depinst/depinst.py timer 59 | - cmd /c bootstrap 60 | - b2 -d0 headers 61 | 62 | build: off 63 | 64 | test_script: 65 | - PATH=%ADDPATH%%PATH% 66 | - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% 67 | - if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% 68 | - if "%CMAKE%" == "" b2 -j3 -l120 --verbose-test libs/timer/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release 69 | 70 | - if not "%CMAKE%" == "" mkdir __build_static && cd __build_static 71 | - if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer .. 72 | - if not "%CMAKE%" == "" cmake --build . --target tests --config Debug && ctest --output-on-failure -C Debug 73 | - if not "%CMAKE%" == "" cmake --build . --target tests --config Release && ctest --output-on-failure -C Release 74 | - if not "%CMAKE%" == "" cmake --build . --target tests --config MinSizeRel && ctest --output-on-failure -C MinSizeRel 75 | - if not "%CMAKE%" == "" cmake --build . --target tests --config RelWithDebInfo && ctest --output-on-failure -C RelWithDebInfo 76 | 77 | - if not "%CMAKE%" == "" cd .. 78 | 79 | - if not "%CMAKE%" == "" mkdir __build_shared && cd __build_shared 80 | - if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=timer -DBUILD_SHARED_LIBS=ON .. 81 | - if not "%CMAKE%" == "" cmake --build . --target tests --config Debug && ctest --output-on-failure -C Debug 82 | - if not "%CMAKE%" == "" cmake --build . --target tests --config Release && ctest --output-on-failure -C Release 83 | - if not "%CMAKE%" == "" cmake --build . --target tests --config MinSizeRel && ctest --output-on-failure -C MinSizeRel 84 | - if not "%CMAKE%" == "" cmake --build . --target tests --config RelWithDebInfo && ctest --output-on-failure -C RelWithDebInfo 85 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 René Ferdinand Rivera Morell 2 | # Copyright 2024 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/config//boost_config 10 | ; 11 | 12 | project /boost/timer ; 13 | 14 | explicit 15 | [ alias boost_timer : build//boost_timer ] 16 | [ alias all : boost_timer build test ] 17 | ; 18 | 19 | call-if : boost-library timer 20 | : install boost_timer 21 | ; 22 | -------------------------------------------------------------------------------- /build/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Timer Library Build Jamfile 2 | 3 | # (C) Copyright Beman Dawes 2002, 2006, 2011 4 | 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See www.boost.org/LICENSE_1_0.txt 7 | 8 | # See library home page at http://www.boost.org/libs/timer 9 | 10 | constant boost_dependencies_private : 11 | /boost/io//boost_io 12 | /boost/predef//boost_predef 13 | ; 14 | 15 | project 16 | : common-requirements 17 | 18 | ../include 19 | 20 | $(boost_dependencies) 21 | 22 | shared:BOOST_TIMER_DYN_LINK=1 23 | static:BOOST_TIMER_STATIC_LINK=1 24 | 25 | BOOST_TIMER_NO_LIB=1 26 | 27 | : requirements 28 | 29 | $(boost_dependencies_private) 30 | ; 31 | 32 | local SOURCES = auto_timers_construction cpu_timer ; 33 | 34 | lib boost_timer : ../src/$(SOURCES).cpp ; 35 | -------------------------------------------------------------------------------- /doc/cpu_timers.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/timer/b7f65f09a0975f26cb294eebd8b17e91a5beff3f/doc/cpu_timers.html -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/timer/b7f65f09a0975f26cb294eebd8b17e91a5beff3f/doc/index.html -------------------------------------------------------------------------------- /doc/original_timer.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/timer/b7f65f09a0975f26cb294eebd8b17e91a5beff3f/doc/original_timer.html -------------------------------------------------------------------------------- /example/auto_cpu_timer_example.cpp: -------------------------------------------------------------------------------- 1 | // auto_cpu_timer_example.cpp ------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2006 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | boost::timer::auto_cpu_timer t; 14 | 15 | for ( long i = 0; i < 100000000; ++i ) 16 | std::sqrt( 123.456L ); // burn some time 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /example/timex.cpp: -------------------------------------------------------------------------------- 1 | // timex: timed execution program ------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2007 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See http://www.boost.org/libs/timer for documentation. 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main( int argc, char * argv[] ) 16 | { 17 | if ( argc == 1 ) 18 | { 19 | std::cout << "invoke: timex [-v] command [args...]\n" 20 | " command will be executed and timings displayed\n" 21 | " -v option causes command and args to be displayed\n"; 22 | return 1; 23 | } 24 | 25 | std::string s; 26 | 27 | bool verbose = false; 28 | if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' ) 29 | { 30 | verbose = true; 31 | ++argv; 32 | --argc; 33 | } 34 | 35 | for ( int i = 1; i < argc; ++i ) 36 | { 37 | if ( i > 1 ) s += ' '; 38 | s += argv[i]; 39 | } 40 | 41 | if ( verbose ) 42 | { std::cout << "command: \"" << s.c_str() << "\"\n"; } 43 | 44 | boost::timer::auto_cpu_timer t(" %ws elapsed wall-clock time\n"); 45 | 46 | return std::system( s.c_str() ); 47 | } 48 | -------------------------------------------------------------------------------- /include/boost/progress.hpp: -------------------------------------------------------------------------------- 1 | // boost progress.hpp header file ------------------------------------------// 2 | 3 | // Copyright Beman Dawes 1994-99. Distributed under the Boost 4 | // Software License, Version 1.0. (See accompanying file 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // See http://www.boost.org/libs/timer for documentation. 8 | 9 | // Revision History 10 | // 1 Dec 01 Add leading progress display strings (suggested by Toon Knapen) 11 | // 20 May 01 Introduce several static_casts<> to eliminate warning messages 12 | // (Fixed by Beman, reported by Herve Bronnimann) 13 | // 12 Jan 01 Change to inline implementation to allow use without library 14 | // builds. See docs for more rationale. (Beman Dawes) 15 | // 22 Jul 99 Name changed to .hpp 16 | // 16 Jul 99 Second beta 17 | // 6 Jul 99 Initial boost version 18 | 19 | #ifndef BOOST_PROGRESS_HPP 20 | #define BOOST_PROGRESS_HPP 21 | 22 | #if !defined(BOOST_TIMER_ENABLE_DEPRECATED) 23 | # error This header is deprecated and will be removed. (You can define BOOST_TIMER_ENABLE_DEPRECATED to suppress this error.) 24 | #endif 25 | 26 | #include 27 | BOOST_HEADER_DEPRECATED( "the facilities in or " ) 28 | 29 | #include 30 | #include // for uintmax_t 31 | #include // for ostream, cout, etc 32 | #include // for string 33 | 34 | namespace boost { 35 | 36 | // progress_timer ----------------------------------------------------------// 37 | 38 | // A progress_timer behaves like a timer except that the destructor displays 39 | // an elapsed time message at an appropriate place in an appropriate form. 40 | 41 | class progress_timer : public timer 42 | { 43 | private: 44 | 45 | progress_timer( progress_timer const& ); 46 | progress_timer& operator=( progress_timer const& ); 47 | 48 | public: 49 | explicit progress_timer( std::ostream & os = std::cout ) 50 | // os is hint; implementation may ignore, particularly in embedded systems 51 | : timer(), m_os(os) {} 52 | ~progress_timer() 53 | { 54 | // A) Throwing an exception from a destructor is a Bad Thing. 55 | // B) The progress_timer destructor does output which may throw. 56 | // C) A progress_timer is usually not critical to the application. 57 | // Therefore, wrap the I/O in a try block, catch and ignore all exceptions. 58 | try 59 | { 60 | // use istream instead of ios_base to workaround GNU problem (Greg Chicares) 61 | std::istream::fmtflags old_flags = m_os.setf( std::istream::fixed, 62 | std::istream::floatfield ); 63 | std::streamsize old_prec = m_os.precision( 2 ); 64 | m_os << elapsed() << " s\n" // "s" is System International d'Unites std 65 | << std::endl; 66 | m_os.flags( old_flags ); 67 | m_os.precision( old_prec ); 68 | } 69 | 70 | catch (...) {} // eat any exceptions 71 | } // ~progress_timer 72 | 73 | private: 74 | std::ostream & m_os; 75 | }; 76 | 77 | 78 | // progress_display --------------------------------------------------------// 79 | 80 | // progress_display displays an appropriate indication of 81 | // progress at an appropriate place in an appropriate form. 82 | 83 | // NOTE: (Jan 12, 2001) Tried to change unsigned long to boost::uintmax_t, but 84 | // found some compilers couldn't handle the required conversion to double. 85 | // Reverted to unsigned long until the compilers catch up. 86 | 87 | class progress_display 88 | { 89 | private: 90 | 91 | progress_display( progress_display const& ); 92 | progress_display& operator=( progress_display const& ); 93 | 94 | public: 95 | explicit progress_display( unsigned long expected_count_, 96 | std::ostream & os = std::cout, 97 | const std::string & s1 = "\n", //leading strings 98 | const std::string & s2 = "", 99 | const std::string & s3 = "" ) 100 | // os is hint; implementation may ignore, particularly in embedded systems 101 | : m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count_); } 102 | 103 | void restart( unsigned long expected_count_ ) 104 | // Effects: display appropriate scale 105 | // Postconditions: count()==0, expected_count()==expected_count_ 106 | { 107 | _count = _next_tic_count = _tic = 0; 108 | _expected_count = expected_count_; 109 | 110 | m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n" 111 | << m_s2 << "|----|----|----|----|----|----|----|----|----|----|" 112 | << std::endl // endl implies flush, which ensures display 113 | << m_s3; 114 | if ( !_expected_count ) _expected_count = 1; // prevent divide by zero 115 | } // restart 116 | 117 | unsigned long operator+=( unsigned long increment ) 118 | // Effects: Display appropriate progress tic if needed. 119 | // Postconditions: count()== original count() + increment 120 | // Returns: count(). 121 | { 122 | if ( (_count += increment) >= _next_tic_count ) { display_tic(); } 123 | return _count; 124 | } 125 | 126 | unsigned long operator++() { return operator+=( 1 ); } 127 | unsigned long count() const { return _count; } 128 | unsigned long expected_count() const { return _expected_count; } 129 | 130 | private: 131 | std::ostream & m_os; // may not be present in all imps 132 | const std::string m_s1; // string is more general, safer than 133 | const std::string m_s2; // const char *, and efficiency or size are 134 | const std::string m_s3; // not issues 135 | 136 | unsigned long _count, _expected_count, _next_tic_count; 137 | unsigned int _tic; 138 | void display_tic() 139 | { 140 | // use of floating point ensures that both large and small counts 141 | // work correctly. static_cast<>() is also used several places 142 | // to suppress spurious compiler warnings. 143 | unsigned int tics_needed = static_cast((static_cast(_count) 144 | / static_cast(_expected_count)) * 50.0); 145 | do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed ); 146 | _next_tic_count = 147 | static_cast((_tic/50.0) * static_cast(_expected_count)); 148 | if ( _count == _expected_count ) { 149 | if ( _tic < 51 ) m_os << '*'; 150 | m_os << std::endl; 151 | } 152 | } // display_tic 153 | }; 154 | 155 | } // namespace boost 156 | 157 | #endif // BOOST_PROGRESS_HPP 158 | -------------------------------------------------------------------------------- /include/boost/timer.hpp: -------------------------------------------------------------------------------- 1 | // boost timer.hpp header file ---------------------------------------------// 2 | 3 | // Copyright Beman Dawes 1994-99. Distributed under the Boost 4 | // Software License, Version 1.0. (See accompanying file 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // See http://www.boost.org/libs/timer for documentation. 8 | 9 | // Revision History 10 | // 01 Apr 01 Modified to use new header. (JMaddock) 11 | // 12 Jan 01 Change to inline implementation to allow use without library 12 | // builds. See docs for more rationale. (Beman Dawes) 13 | // 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock) 14 | // 16 Jul 99 Second beta 15 | // 6 Jul 99 Initial boost version 16 | 17 | #ifndef BOOST_TIMER_HPP 18 | #define BOOST_TIMER_HPP 19 | 20 | #if !defined(BOOST_TIMER_ENABLE_DEPRECATED) 21 | # error This header is deprecated and will be removed. (You can define BOOST_TIMER_ENABLE_DEPRECATED to suppress this error.) 22 | #endif 23 | 24 | #include 25 | BOOST_HEADER_DEPRECATED( "the facilities in " ) 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | # ifdef BOOST_NO_STDC_NAMESPACE 32 | namespace std { using ::clock_t; using ::clock; } 33 | # endif 34 | 35 | 36 | namespace boost { 37 | 38 | // timer -------------------------------------------------------------------// 39 | 40 | // A timer object measures elapsed time. 41 | 42 | // It is recommended that implementations measure wall clock rather than CPU 43 | // time since the intended use is performance measurement on systems where 44 | // total elapsed time is more important than just process or CPU time. 45 | 46 | // Warnings: The maximum measurable elapsed time may well be only 596.5+ hours 47 | // due to implementation limitations. The accuracy of timings depends on the 48 | // accuracy of timing information provided by the underlying platform, and 49 | // this varies a great deal from platform to platform. 50 | 51 | class timer 52 | { 53 | public: 54 | timer() { _start_time = std::clock(); } // postcondition: elapsed()==0 55 | // timer( const timer& src ); // post: elapsed()==src.elapsed() 56 | // ~timer(){} 57 | // timer& operator=( const timer& src ); // post: elapsed()==src.elapsed() 58 | void restart() { _start_time = std::clock(); } // post: elapsed()==0 59 | double elapsed() const // return elapsed time in seconds 60 | { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; } 61 | 62 | double elapsed_max() const // return estimated maximum value for elapsed() 63 | // Portability warning: elapsed_max() may return too high a value on systems 64 | // where std::clock_t overflows or resets at surprising values. 65 | { 66 | return (double((std::numeric_limits::max)()) 67 | - double(_start_time)) / double(CLOCKS_PER_SEC); 68 | } 69 | 70 | double elapsed_min() const // return minimum value for elapsed() 71 | { return double(1)/double(CLOCKS_PER_SEC); } 72 | 73 | private: 74 | std::clock_t _start_time; 75 | }; // timer 76 | 77 | } // namespace boost 78 | 79 | #endif // BOOST_TIMER_HPP 80 | -------------------------------------------------------------------------------- /include/boost/timer/config.hpp: -------------------------------------------------------------------------------- 1 | // boost/timer/config.hpp -----------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2003, 2006, 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See http://www.boost.org/libs/timer for documentation. 9 | 10 | #ifndef BOOST_TIMER_CONFIG_HPP 11 | #define BOOST_TIMER_CONFIG_HPP 12 | 13 | #include 14 | 15 | // This header implements separate compilation features as described in 16 | // http://www.boost.org/more/separate_compilation.html 17 | 18 | // enable dynamic or static linking as requested --------------------------------------// 19 | 20 | #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TIMER_DYN_LINK) 21 | # if defined(BOOST_TIMER_SOURCE) 22 | # define BOOST_TIMER_DECL BOOST_SYMBOL_EXPORT 23 | # else 24 | # define BOOST_TIMER_DECL BOOST_SYMBOL_IMPORT 25 | # endif 26 | #else 27 | # define BOOST_TIMER_DECL 28 | #endif 29 | 30 | // enable automatic library variant selection ----------------------------------------// 31 | 32 | #if !defined(BOOST_TIMER_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_TIMER_NO_LIB) 33 | // 34 | // Set the name of our library, this will get undef'ed by auto_link.hpp 35 | // once it's done with it: 36 | // 37 | #define BOOST_LIB_NAME boost_timer 38 | // 39 | // If we're importing code from a dll, then tell auto_link.hpp about it: 40 | // 41 | #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TIMER_DYN_LINK) 42 | # define BOOST_DYN_LINK 43 | #endif 44 | // 45 | // And include the header that does the work: 46 | // 47 | #include 48 | 49 | #endif // auto-linking disabled 50 | 51 | #endif // BOOST_TIMER_CONFIG_HPP 52 | -------------------------------------------------------------------------------- /include/boost/timer/progress_display.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Beman Dawes 1994-99. 3 | // Copyright Peter Dimov 2019. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // See http://www.boost.org/libs/timer for documentation. 8 | 9 | #ifndef BOOST_TIMER_PROGRESS_DISPLAY_HPP_INCLUDED 10 | #define BOOST_TIMER_PROGRESS_DISPLAY_HPP_INCLUDED 11 | 12 | #include // for ostream, cout, etc 13 | #include // for string 14 | 15 | namespace boost { 16 | namespace timer { 17 | 18 | // progress_display --------------------------------------------------------// 19 | 20 | // progress_display displays an appropriate indication of 21 | // progress at an appropriate place in an appropriate form. 22 | 23 | class progress_display 24 | { 25 | private: 26 | 27 | progress_display( progress_display const& ); 28 | progress_display& operator=( progress_display const& ); 29 | 30 | public: 31 | explicit progress_display( unsigned long expected_count_, 32 | std::ostream & os = std::cout, 33 | const std::string & s1 = "\n", //leading strings 34 | const std::string & s2 = "", 35 | const std::string & s3 = "" ) 36 | // os is hint; implementation may ignore, particularly in embedded systems 37 | : m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count_); } 38 | 39 | void restart( unsigned long expected_count_ ) 40 | // Effects: display appropriate scale 41 | // Postconditions: count()==0, expected_count()==expected_count_ 42 | { 43 | _count = _next_tic_count = _tic = 0; 44 | _expected_count = expected_count_; 45 | 46 | m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n" 47 | << m_s2 << "|----|----|----|----|----|----|----|----|----|----|" 48 | << std::endl // endl implies flush, which ensures display 49 | << m_s3; 50 | if ( !_expected_count ) _expected_count = 1; // prevent divide by zero 51 | } // restart 52 | 53 | unsigned long operator+=( unsigned long increment ) 54 | // Effects: Display appropriate progress tic if needed. 55 | // Postconditions: count()== original count() + increment 56 | // Returns: count(). 57 | { 58 | if ( (_count += increment) >= _next_tic_count ) { display_tic(); } 59 | return _count; 60 | } 61 | 62 | unsigned long operator++() { return operator+=( 1 ); } 63 | unsigned long count() const { return _count; } 64 | unsigned long expected_count() const { return _expected_count; } 65 | 66 | private: 67 | std::ostream & m_os; // may not be present in all imps 68 | const std::string m_s1; // string is more general, safer than 69 | const std::string m_s2; // const char *, and efficiency or size are 70 | const std::string m_s3; // not issues 71 | 72 | unsigned long _count, _expected_count, _next_tic_count; 73 | unsigned int _tic; 74 | void display_tic() 75 | { 76 | // use of floating point ensures that both large and small counts 77 | // work correctly. static_cast<>() is also used several places 78 | // to suppress spurious compiler warnings. 79 | unsigned int tics_needed = static_cast((static_cast(_count) 80 | / static_cast(_expected_count)) * 50.0); 81 | do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed ); 82 | _next_tic_count = 83 | static_cast((_tic/50.0) * static_cast(_expected_count)); 84 | if ( _count == _expected_count ) { 85 | if ( _tic < 51 ) m_os << '*'; 86 | m_os << std::endl; 87 | } 88 | } // display_tic 89 | }; 90 | 91 | } // namespace timer 92 | } // namespace boost 93 | 94 | #endif // BOOST_TIMER_PROGRESS_DISPLAY_HPP_INCLUDED 95 | -------------------------------------------------------------------------------- /include/boost/timer/timer.hpp: -------------------------------------------------------------------------------- 1 | // boost/timer/timer.hpp -------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 1994-2007, 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | #ifndef BOOST_TIMER_TIMER_HPP 9 | #define BOOST_TIMER_TIMER_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include // must be the last #include 18 | 19 | # if defined(_MSC_VER) 20 | # pragma warning(push) // Save warning settings 21 | # pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>' 22 | # endif // needs to have dll-interface... 23 | 24 | //--------------------------------------------------------------------------------------// 25 | 26 | namespace boost 27 | { 28 | namespace timer 29 | { 30 | class cpu_timer; 31 | class auto_cpu_timer; 32 | 33 | typedef boost::int_least64_t nanosecond_type; 34 | 35 | struct cpu_times 36 | { 37 | nanosecond_type wall; 38 | nanosecond_type user; 39 | nanosecond_type system; 40 | 41 | void clear() { wall = user = system = 0; } 42 | }; 43 | 44 | const short default_places = 6; 45 | 46 | BOOST_TIMER_DECL 47 | std::string format(const cpu_times& times, short places, const std::string& format); 48 | 49 | BOOST_TIMER_DECL 50 | std::string format(const cpu_times& times, short places = default_places); 51 | 52 | // cpu_timer -------------------------------------------------------------------------// 53 | 54 | class BOOST_TIMER_DECL cpu_timer 55 | { 56 | public: 57 | 58 | // constructor 59 | cpu_timer() BOOST_NOEXCEPT { start(); } 60 | 61 | // observers 62 | bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; } 63 | cpu_times elapsed() const BOOST_NOEXCEPT; // does not stop() 64 | std::string format(short places, const std::string& format) const 65 | { return ::boost::timer::format(elapsed(), places, format); } 66 | std::string format(short places = default_places) const 67 | { return ::boost::timer::format(elapsed(), places); } 68 | // actions 69 | void start() BOOST_NOEXCEPT; 70 | void stop() BOOST_NOEXCEPT; 71 | void resume() BOOST_NOEXCEPT; 72 | 73 | private: 74 | cpu_times m_times; 75 | bool m_is_stopped; 76 | }; 77 | 78 | // auto_cpu_timer --------------------------------------------------------------------// 79 | 80 | class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer 81 | { 82 | public: 83 | 84 | // Explicit defaults for os are not provided to avoid including , which has 85 | // high costs even when the standard streams are not actually used. Explicit defaults 86 | // for format are not provided to avoid order-of-dynamic-initialization issues with a 87 | // std::string. 88 | 89 | explicit auto_cpu_timer(short places = default_places); // #1 90 | auto_cpu_timer(short places, const std::string& format); // #2 91 | explicit auto_cpu_timer(const std::string& format); // #3 92 | auto_cpu_timer(std::ostream& os, short places, 93 | const std::string& format) // #4 94 | : m_places(places), m_os(&os), m_format(format) 95 | { start(); } 96 | explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5 97 | auto_cpu_timer(std::ostream& os, const std::string& format) // #6 98 | : m_places(default_places), m_os(&os), m_format(format) 99 | { start(); } 100 | 101 | ~auto_cpu_timer(); 102 | 103 | // observers 104 | // not particularly useful to users, but allow testing of constructor 105 | // postconditions and ease specification of other functionality without resorting 106 | // to "for exposition only" private members. 107 | std::ostream& ostream() const { return *m_os; } 108 | short places() const { return m_places; } 109 | const std::string& format_string() const { return m_format; } 110 | 111 | // actions 112 | void report(); 113 | 114 | private: 115 | short m_places; 116 | std::ostream* m_os; // stored as ptr so compiler can generate operator= 117 | std::string m_format; 118 | }; 119 | 120 | } // namespace timer 121 | } // namespace boost 122 | 123 | # if defined(_MSC_VER) 124 | # pragma warning(pop) // restore warning settings. 125 | # endif 126 | 127 | #include // pops abi_prefix.hpp pragmas 128 | 129 | #endif // BOOST_TIMER_TIMER_HPP 130 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Automatic redirection failed, please go to doc/index.html. 7 |
8 |

© Copyright Beman Dawes, 2003, 2011

9 |

Distributed under the Boost Software 10 | License, Version 1.0.

11 |

See 12 | www.boost.org/LICENSE_1_0.txt

13 | 14 | 15 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "timer", 3 | "name": "Timer", 4 | "authors": [ 5 | "Beman Dawes" 6 | ], 7 | "description": "Event timer, progress timer, and progress display classes.", 8 | "category": [ 9 | "Miscellaneous" 10 | ], 11 | "maintainers": [ 12 | "Peter Dimov " 13 | ], 14 | "cxxstd": "03" 15 | } 16 | -------------------------------------------------------------------------------- /src/auto_timers_construction.cpp: -------------------------------------------------------------------------------- 1 | // boost auto_timers_construction.cpp ------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2007, 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | // See http://www.boost.org/libs/timer for documentation. 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | // These constructors are in a separate file so that this translation unit will 13 | // not be linked in except when one of the constructors is actually used. This 14 | // is important since header is required, and it incurs the cost of 15 | // the standard stream objects even if they are not used. 16 | 17 | //--------------------------------------------------------------------------------------// 18 | 19 | // define BOOST_TIMER_SOURCE so that knows 20 | // the library is being built (possibly exporting rather than importing code) 21 | #ifndef BOOST_TIMER_SOURCE 22 | # define BOOST_TIMER_SOURCE 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | namespace 29 | { 30 | // CAUTION: must be identical to same constant in cpu_timer.cpp 31 | const std::string default_fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n"); 32 | } 33 | 34 | namespace boost 35 | { 36 | namespace timer 37 | { 38 | auto_cpu_timer::auto_cpu_timer(short places) // #1 39 | : m_places(places), m_os(&std::cout), m_format(default_fmt) { start(); } 40 | 41 | auto_cpu_timer::auto_cpu_timer(short places, const std::string& format) // #2 42 | : m_places(places), m_os(&std::cout), m_format(format) { start(); } 43 | 44 | auto_cpu_timer::auto_cpu_timer(const std::string& format) // #3 45 | : m_places(default_places), m_os(&std::cout), m_format(format) { start(); } 46 | 47 | } // namespace timer 48 | } // namespace boost 49 | -------------------------------------------------------------------------------- /src/cpu_timer.cpp: -------------------------------------------------------------------------------- 1 | // boost cpu_timer.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 1994-2006, 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | // See http://www.boost.org/libs/timer for documentation. 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | // define BOOST_TIMER_SOURCE so that knows 13 | // the library is being built (possibly exporting rather than importing code) 14 | #ifndef BOOST_TIMER_SOURCE 15 | # define BOOST_TIMER_SOURCE 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #if defined(_WIN32) 27 | # include 28 | #else 29 | # include 30 | # include 31 | #endif 32 | 33 | using boost::timer::nanosecond_type; 34 | using boost::timer::cpu_times; 35 | 36 | namespace 37 | { 38 | 39 | void show_time(const cpu_times& times, 40 | std::ostream& os, const std::string& fmt, short places) 41 | // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may 42 | // be as low as 10, although will be 15 for many common platforms. 43 | { 44 | if (places > 9) 45 | places = 9; 46 | else if (places < 0) 47 | places = boost::timer::default_places; 48 | 49 | boost::io::ios_flags_saver ifs(os); 50 | boost::io::ios_precision_saver ips(os); 51 | os.setf(std::ios_base::fixed, std::ios_base::floatfield); 52 | os.precision(places); 53 | 54 | const double sec = 1000000000.0L; 55 | nanosecond_type total = times.system + times.user; 56 | double wall_sec = static_cast(times.wall) / sec; 57 | double total_sec = static_cast(total) / sec; 58 | 59 | for (const char* format = fmt.c_str(); *format; ++format) 60 | { 61 | if (*format != '%' || !*(format+1) || !std::strchr("wustp", *(format+1))) 62 | os << *format; // anything except % followed by a valid format character 63 | // gets sent to the output stream 64 | else 65 | { 66 | ++format; 67 | switch (*format) 68 | { 69 | case 'w': 70 | os << wall_sec; 71 | break; 72 | case 'u': 73 | os << static_cast(times.user) / sec; 74 | break; 75 | case 's': 76 | os << static_cast(times.system) / sec; 77 | break; 78 | case 't': 79 | os << total_sec; 80 | break; 81 | case 'p': 82 | os.precision(1); 83 | if (wall_sec > 0.001L && total_sec > 0.001L) 84 | os << (total_sec/wall_sec) * 100.0; 85 | else 86 | os << "n/a"; 87 | os.precision(places); 88 | break; 89 | } 90 | } 91 | } 92 | } 93 | 94 | #if defined(_WIN32) 95 | 96 | boost::long_long_type query_performance_frequency() 97 | { 98 | LARGE_INTEGER li; 99 | ::QueryPerformanceFrequency( &li ); // never fails 100 | 101 | return li.QuadPart; 102 | } 103 | 104 | void get_cpu_times( boost::timer::cpu_times& current ) 105 | { 106 | static const boost::long_long_type freq = query_performance_frequency(); 107 | 108 | LARGE_INTEGER li; 109 | ::QueryPerformanceCounter( &li ); // never fails 110 | 111 | boost::long_long_type ctr = li.QuadPart; 112 | 113 | boost::long_long_type const nano = INT64_C( 1000000000 ); // ns 114 | 115 | // ctr * nano / freq, but with less overflow 116 | 117 | boost::long_long_type whole = (ctr / freq) * nano; 118 | boost::long_long_type part = (ctr % freq) * nano / freq; 119 | 120 | current.wall = whole + part; 121 | current.user = boost::timer::nanosecond_type( -1 ); 122 | current.system = boost::timer::nanosecond_type( -1 ); 123 | 124 | #if BOOST_PLAT_WINDOWS_DESKTOP 125 | 126 | FILETIME creation, exit, kernel, user; 127 | 128 | if( !::GetProcessTimes( ::GetCurrentProcess(), &creation, &exit, &kernel, &user ) ) 129 | { 130 | return; 131 | } 132 | 133 | // Windows uses 100 nanosecond ticks 134 | 135 | current.system = ( ( boost::timer::nanosecond_type( kernel.dwHighDateTime ) << 32 ) + kernel.dwLowDateTime ) * 100; 136 | current.user = ( ( boost::timer::nanosecond_type( user.dwHighDateTime ) << 32 ) + user.dwLowDateTime ) * 100; 137 | 138 | #endif 139 | } 140 | 141 | #else 142 | 143 | // multiplier to convert ticks to nanoseconds; -1 if unknown 144 | boost::int_least64_t tick_factor() 145 | { 146 | boost::int_least64_t tf = ::sysconf( _SC_CLK_TCK ); 147 | if( tf <= 0 ) return -1; 148 | 149 | tf = INT64_C( 1000000000 ) / tf; // compute factor 150 | if( tf == 0 ) tf = -1; 151 | 152 | return tf; 153 | } 154 | 155 | void get_cpu_times( boost::timer::cpu_times& current ) 156 | { 157 | current.wall = boost::timer::nanosecond_type( -1 ); 158 | current.user = boost::timer::nanosecond_type( -1 ); 159 | current.system = boost::timer::nanosecond_type( -1 ); 160 | 161 | static boost::int_least64_t tf = tick_factor(); 162 | 163 | if( tf == -1 ) return; 164 | 165 | tms tm; 166 | clock_t c = ::times( &tm ); 167 | 168 | if( c == static_cast( -1 ) ) return; 169 | 170 | current.wall = boost::timer::nanosecond_type( c ) * tf; 171 | current.system = boost::timer::nanosecond_type( tm.tms_stime + tm.tms_cstime ) * tf; 172 | current.user = boost::timer::nanosecond_type( tm.tms_utime + tm.tms_cutime ) * tf; 173 | } 174 | 175 | #endif 176 | 177 | // CAUTION: must be identical to same constant in auto_timers_construction.cpp 178 | const std::string default_fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n"); 179 | 180 | } // unnamed namespace 181 | 182 | namespace boost 183 | { 184 | namespace timer 185 | { 186 | // format ------------------------------------------------------------------------// 187 | 188 | BOOST_TIMER_DECL 189 | std::string format(const cpu_times& times, short places, const std::string& fmt) 190 | { 191 | std::stringstream ss; 192 | ss.exceptions(std::ios_base::badbit | std::ios_base::failbit); 193 | show_time(times, ss, fmt, places); 194 | return ss.str(); 195 | } 196 | 197 | BOOST_TIMER_DECL 198 | std::string format(const cpu_times& times, short places) 199 | { 200 | return format(times, places, default_fmt); 201 | } 202 | 203 | // cpu_timer ---------------------------------------------------------------------// 204 | 205 | void cpu_timer::start() BOOST_NOEXCEPT 206 | { 207 | m_is_stopped = false; 208 | get_cpu_times(m_times); 209 | } 210 | 211 | void cpu_timer::stop() BOOST_NOEXCEPT 212 | { 213 | if (is_stopped()) 214 | return; 215 | m_is_stopped = true; 216 | 217 | cpu_times current; 218 | get_cpu_times(current); 219 | m_times.wall = (current.wall - m_times.wall); 220 | m_times.user = (current.user - m_times.user); 221 | m_times.system = (current.system - m_times.system); 222 | } 223 | 224 | cpu_times cpu_timer::elapsed() const BOOST_NOEXCEPT 225 | { 226 | if (is_stopped()) 227 | return m_times; 228 | cpu_times current; 229 | get_cpu_times(current); 230 | current.wall -= m_times.wall; 231 | current.user -= m_times.user; 232 | current.system -= m_times.system; 233 | return current; 234 | } 235 | 236 | void cpu_timer::resume() BOOST_NOEXCEPT 237 | { 238 | if (is_stopped()) 239 | { 240 | cpu_times current (m_times); 241 | start(); 242 | m_times.wall -= current.wall; 243 | m_times.user -= current.user; 244 | m_times.system -= current.system; 245 | } 246 | } 247 | 248 | // auto_cpu_timer ----------------------------------------------------------------// 249 | 250 | auto_cpu_timer::auto_cpu_timer(std::ostream& os, short places) // #5 251 | : m_places(places), m_os(&os), m_format(default_fmt) 252 | { 253 | start(); 254 | } 255 | 256 | void auto_cpu_timer::report() 257 | { 258 | show_time(elapsed(), ostream(), format_string(), places()); 259 | } 260 | 261 | auto_cpu_timer::~auto_cpu_timer() 262 | { 263 | if (!is_stopped()) 264 | { 265 | stop(); // the sooner we stop(), the better 266 | #ifndef BOOST_NO_EXCEPTIONS 267 | try 268 | { 269 | #endif 270 | report(); 271 | #ifndef BOOST_NO_EXCEPTIONS 272 | } 273 | catch (...) // eat any exceptions 274 | { 275 | } 276 | #endif 277 | } 278 | } 279 | 280 | } // namespace timer 281 | } // namespace boost 282 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018, 2019 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) 6 | 7 | if(HAVE_BOOST_TEST) 8 | 9 | boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::timer Boost::core Boost::detail) 10 | 11 | endif() 12 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Timer Library test Jamfile 2 | 3 | # Copyright Beman Dawes 2003, 2006, 2011 4 | 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | # See library home page at http://www.boost.org/libs/timer 9 | 10 | import testing ; 11 | 12 | path-constant parent : .. ; # so that inspect will start in boost-root/libs/timer 13 | # when run from another directory, such as boost-root/status 14 | 15 | project 16 | : requirements 17 | /boost/timer//boost_timer 18 | /boost/core//boost_core 19 | /boost/detail//boost_detail 20 | ; 21 | 22 | run ../example/auto_cpu_timer_example.cpp 23 | : : : always_show_run_output ; 24 | 25 | run cpu_timer_info.cpp 26 | : : : always_show_run_output ; 27 | 28 | run cpu_timer_test.cpp 29 | : : : always_show_run_output ; 30 | 31 | run ../example/timex.cpp : echo "Hello, world" : : always_show_run_output ; 32 | 33 | compile original_timer_test.cpp ; 34 | 35 | run chrono_conflict_test.cpp : : : /boost/chrono//boost_chrono static ; 36 | 37 | run progress_display_test.cpp ; 38 | 39 | # run /boost/tools/inspect//inspect/release : $(parent) -text -brief : : always_show_run_output : inspect ; 40 | # explicit inspect ; 41 | -------------------------------------------------------------------------------- /test/chrono_conflict_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Peter Dimov. 2 | // 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // 5 | // Check that using Chrono and Timer in the same program does 6 | // not cause link errors. 7 | 8 | 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | boost::chrono::steady_clock::now(); 15 | boost::timer::cpu_timer cpt; 16 | } 17 | -------------------------------------------------------------------------------- /test/cmake_install_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018-2021 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # https://www.boost.org/LICENSE_1_0.txt 4 | 5 | cmake_minimum_required(VERSION 3.5...3.20) 6 | 7 | project(cmake_install_test LANGUAGES CXX) 8 | 9 | find_package(boost_timer REQUIRED) 10 | 11 | add_executable(main main.cpp) 12 | target_link_libraries(main Boost::timer) 13 | 14 | enable_testing() 15 | add_test(main main) 16 | -------------------------------------------------------------------------------- /test/cmake_install_test/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // https://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | 7 | int main() 8 | { 9 | boost::timer::cpu_timer timer; 10 | timer.stop(); 11 | } 12 | -------------------------------------------------------------------------------- /test/cmake_subdir_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018-2021 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | cmake_minimum_required(VERSION 3.5...3.20) 6 | 7 | project(cmake_subdir_test LANGUAGES CXX) 8 | 9 | # Put boost_timer.dll in the same directory as main.exe 10 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 11 | 12 | add_subdirectory(../.. boostorg/timer) 13 | 14 | set(deps 15 | 16 | # Primary dependencies 17 | config 18 | io 19 | predef 20 | ) 21 | 22 | foreach(dep IN LISTS deps) 23 | 24 | add_subdirectory(../../../${dep} boostorg/${dep}) 25 | 26 | endforeach() 27 | 28 | add_executable(main main.cpp) 29 | target_link_libraries(main Boost::timer) 30 | 31 | enable_testing() 32 | add_test(main main) 33 | -------------------------------------------------------------------------------- /test/cmake_subdir_test/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // https://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | 7 | int main() 8 | { 9 | boost::timer::cpu_timer timer; 10 | timer.stop(); 11 | } 12 | -------------------------------------------------------------------------------- /test/cpu_timer_info.cpp: -------------------------------------------------------------------------------- 1 | // boost cpu_timer_info.cpp ----------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See http://www.boost.org/libs/timer for documentation. 9 | 10 | #include 11 | #include 12 | #include // for atol() 13 | #include 14 | #include 15 | 16 | using boost::timer::nanosecond_type; 17 | using boost::timer::cpu_times; 18 | using boost::timer::cpu_timer; 19 | using boost::timer::auto_cpu_timer; 20 | using std::cout; using std::endl; 21 | 22 | int cpp_main( int argc, char * argv[] ) 23 | { 24 | cpu_times start_time; 25 | start_time.clear(); 26 | cpu_times current_time; 27 | 28 | { 29 | cpu_timer cpu; 30 | cout << "measure boost::timer::cpu_timer resolution for user time..." 31 | << endl; 32 | for (int i = 0; i < 3; ++i) 33 | { 34 | cpu.start(); 35 | start_time = cpu.elapsed(); 36 | current_time.user = start_time.user; 37 | while (current_time.user == start_time.user) 38 | { 39 | current_time = cpu.elapsed(); 40 | } 41 | cout << current_time.user - start_time.user << "ns\n"; 42 | } 43 | } 44 | 45 | { 46 | cpu_timer cpu; 47 | cout << "measure boost::timer::cpu_timer resolution for wall-clock time..." 48 | << endl; 49 | for (int i = 0; i < 100; ++i) 50 | { 51 | cpu.start(); 52 | start_time.wall = cpu.elapsed().wall; 53 | current_time.wall = start_time.wall; 54 | while (current_time.wall == start_time.wall) 55 | { 56 | current_time.wall = cpu.elapsed().wall; 57 | } 58 | cout << current_time.wall - start_time.wall << "ns "; 59 | } 60 | } 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /test/cpu_timer_test.cpp: -------------------------------------------------------------------------------- 1 | // boost timer_test.cpp --------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2006, 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See http://www.boost.org/libs/timer for documentation. 9 | 10 | #include 11 | #include 12 | #include 13 | #include // for atol() 14 | #include 15 | #include 16 | #include 17 | 18 | using std::string; 19 | using std::cout; 20 | using std::endl; 21 | using boost::timer::default_places; 22 | using boost::timer::nanosecond_type; 23 | using boost::timer::cpu_times; 24 | using boost::timer::format; 25 | using boost::timer::cpu_timer; 26 | using boost::timer::auto_cpu_timer; 27 | 28 | namespace 29 | { 30 | void unit_test() 31 | { 32 | cout << "unit test..." << endl; 33 | 34 | string default_format(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n"); 35 | 36 | // each constructor 37 | auto_cpu_timer t1; 38 | BOOST_TEST(!t1.is_stopped()); 39 | // the following, and similar below, are giving false failures on MinGW/gcc 40 | // so comment them out for now 41 | //BOOST_TEST(&t1.ostream() == &cout); 42 | BOOST_TEST_EQ(t1.places(), default_places); 43 | BOOST_TEST_EQ(t1.format_string(), default_format); 44 | t1.stop(); 45 | BOOST_TEST(t1.is_stopped()); 46 | auto_cpu_timer t1a(t1); 47 | BOOST_TEST(t1a.is_stopped()); 48 | BOOST_TEST_EQ(t1a.elapsed().wall, t1.elapsed().wall); 49 | BOOST_TEST_EQ(t1a.elapsed().user, t1.elapsed().user); 50 | BOOST_TEST_EQ(t1a.elapsed().system, t1.elapsed().system); 51 | //BOOST_TEST(&t1a.ostream() == &cout); 52 | BOOST_TEST_EQ(t1a.places(), default_places); 53 | BOOST_TEST_EQ(t1a.format_string(), default_format); 54 | 55 | auto_cpu_timer t1b; 56 | BOOST_TEST(!t1b.is_stopped()); 57 | t1b = t1; 58 | BOOST_TEST(t1b.is_stopped()); 59 | BOOST_TEST_EQ(t1b.elapsed().wall, t1.elapsed().wall); 60 | BOOST_TEST_EQ(t1b.elapsed().user, t1.elapsed().user); 61 | BOOST_TEST_EQ(t1b.elapsed().system, t1.elapsed().system); 62 | //BOOST_TEST(&t1b.ostream() == &cout); 63 | BOOST_TEST_EQ(t1b.places(), default_places); 64 | BOOST_TEST_EQ(t1b.format_string(), default_format); 65 | 66 | auto_cpu_timer t2(1); 67 | BOOST_TEST(!t2.is_stopped()); 68 | //BOOST_TEST(&t2.ostream() == &cout); 69 | BOOST_TEST_EQ(t2.places(), 1); 70 | BOOST_TEST_EQ(t2.format_string(), default_format); 71 | 72 | auto_cpu_timer t3("foo"); 73 | BOOST_TEST(!t3.is_stopped()); 74 | //BOOST_TEST(&t3.ostream() == &cout); 75 | BOOST_TEST_EQ(t3.places(), default_places); 76 | BOOST_TEST_EQ(t3.format_string(), string("foo")); 77 | 78 | auto_cpu_timer t4(1, "foo"); 79 | BOOST_TEST(!t4.is_stopped()); 80 | //BOOST_TEST(&t4.ostream() == &cout); 81 | BOOST_TEST_EQ(t4.places(), 1); 82 | BOOST_TEST_EQ(t4.format_string(), string("foo")); 83 | 84 | auto_cpu_timer t5(std::cerr); 85 | BOOST_TEST(!t5.is_stopped()); 86 | BOOST_TEST(&t5.ostream() == &std::cerr); 87 | BOOST_TEST_EQ(t5.places(), default_places); 88 | BOOST_TEST_EQ(t5.format_string(), default_format); 89 | 90 | auto_cpu_timer t6(std::cerr, 1); 91 | BOOST_TEST(!t6.is_stopped()); 92 | BOOST_TEST(&t6.ostream() == &std::cerr); 93 | BOOST_TEST_EQ(t6.places(), 1); 94 | BOOST_TEST_EQ(t6.format_string(), default_format); 95 | 96 | auto_cpu_timer t7(std::cerr, "foo"); 97 | BOOST_TEST(!t7.is_stopped()); 98 | BOOST_TEST(&t7.ostream() == &std::cerr); 99 | BOOST_TEST_EQ(t7.places(), default_places); 100 | BOOST_TEST_EQ(t7.format_string(), string("foo")); 101 | 102 | auto_cpu_timer t8(std::cerr, 1, "foo"); 103 | BOOST_TEST(!t8.is_stopped()); 104 | BOOST_TEST(&t8.ostream() == &std::cerr); 105 | BOOST_TEST_EQ(t8.places(), 1); 106 | BOOST_TEST_EQ(t8.format_string(), string("foo")); 107 | 108 | t1.stop(); 109 | t1a.stop(); 110 | t1b.stop(); 111 | t2.stop(); 112 | t3.stop(); 113 | t4.stop(); 114 | t5.stop(); 115 | t6.stop(); 116 | t7.stop(); 117 | t8.stop(); 118 | 119 | cout << " unit test complete" << endl; 120 | } 121 | 122 | void format_test() 123 | { 124 | cout << "format test..." << endl; 125 | 126 | cpu_times times; 127 | times.wall = 5123456789LL; 128 | times.user = 2123456789LL; 129 | times.system = 1234567890LL; 130 | 131 | cout << " times.wall is " << times.wall << '\n'; 132 | cout << " times.user is " << times.user << '\n'; 133 | cout << " times.system is " << times.system << '\n'; 134 | cout << " user+system is " << times.user + times.system << '\n'; 135 | cout << " format(times, 9) output: " << format(times, 9); 136 | 137 | BOOST_TEST_EQ(format(times, 9), 138 | string(" 5.123456789s wall, 2.123456789s user + 1.234567890s system = 3.358024679s CPU (65.5%)\n")); 139 | BOOST_TEST_EQ(format(times, 8), 140 | string(" 5.12345679s wall, 2.12345679s user + 1.23456789s system = 3.35802468s CPU (65.5%)\n")); 141 | BOOST_TEST_EQ(format(times, 7), 142 | string(" 5.1234568s wall, 2.1234568s user + 1.2345679s system = 3.3580247s CPU (65.5%)\n")); 143 | BOOST_TEST_EQ(format(times, 6), 144 | string(" 5.123457s wall, 2.123457s user + 1.234568s system = 3.358025s CPU (65.5%)\n")); 145 | BOOST_TEST_EQ(format(times, 5), 146 | string(" 5.12346s wall, 2.12346s user + 1.23457s system = 3.35802s CPU (65.5%)\n")); 147 | BOOST_TEST_EQ(format(times, 4), 148 | string(" 5.1235s wall, 2.1235s user + 1.2346s system = 3.3580s CPU (65.5%)\n")); 149 | BOOST_TEST_EQ(format(times, 3), 150 | string(" 5.123s wall, 2.123s user + 1.235s system = 3.358s CPU (65.5%)\n")); 151 | BOOST_TEST_EQ(format(times, 2), 152 | string(" 5.12s wall, 2.12s user + 1.23s system = 3.36s CPU (65.5%)\n")); 153 | BOOST_TEST_EQ(format(times, 1), 154 | string(" 5.1s wall, 2.1s user + 1.2s system = 3.4s CPU (65.5%)\n")); 155 | BOOST_TEST_EQ(format(times, 0), 156 | string(" 5s wall, 2s user + 1s system = 3s CPU (65.5%)\n")); 157 | BOOST_TEST_EQ(format(times, 10), 158 | string(" 5.123456789s wall, 2.123456789s user + 1.234567890s system = 3.358024679s CPU (65.5%)\n")); 159 | BOOST_TEST_EQ(format(times, -1), 160 | string(" 5.123457s wall, 2.123457s user + 1.234568s system = 3.358025s CPU (65.5%)\n")); 161 | BOOST_TEST_EQ(format(times), 162 | string(" 5.123457s wall, 2.123457s user + 1.234568s system = 3.358025s CPU (65.5%)\n")); 163 | 164 | BOOST_TEST_EQ(format(times, 5, " %w, %u, %s, %t, %%p%"), 165 | string(" 5.12346, 2.12346, 1.23457, 3.35802, %65.5%")); 166 | 167 | BOOST_TEST_EQ(format(times, 5, "boo"), string("boo")); 168 | 169 | cout << " format test complete" << endl; 170 | } 171 | 172 | void std_c_consistency_test() 173 | { 174 | cout << "C library consistency test..." << endl; 175 | 176 | // This test is designed to account for C timer resolution and for the possibility 177 | // that another active process may take up a lot of time. 178 | 179 | cpu_timer t; // calls start(), so ensures any cpu_timer dll loaded 180 | std::time(0); // ensure any system dll's loaded 181 | 182 | std::time_t stop_time, start_time = std::time(0); 183 | 184 | // wait until the time() clock ticks 185 | while (std::time(0) == start_time) {} 186 | 187 | // start both timers 188 | start_time = std::time(0); 189 | t.start(); 190 | 191 | // wait until the time() clock ticks again 192 | while (std::time(0) == start_time) {} 193 | 194 | // stop both timers 195 | stop_time = std::time(0); 196 | t.stop(); 197 | 198 | cout << " std::time() elapsed is " << (stop_time - start_time) * 1.0L << " seconds\n"; 199 | cout << " cpu_timer wall elapsed is " << t.elapsed().wall / 1000000000.0L << " seconds\n"; 200 | cout << " The two clocks whose elapsed time is compared by this test are started\n" 201 | " and stopped one right after the other. If the operating system suspends\n" 202 | " the process in the interim, the test may fail. Thus no single failure\n" 203 | " of this test is meaningful.\n"; 204 | 205 | // These tests allow lots of fuzz to reduce false positives 206 | BOOST_TEST(t.elapsed().wall / 1000000000.0L > (stop_time - start_time) * 0.75L); 207 | BOOST_TEST(t.elapsed().wall / 1000000000.0L < (stop_time - start_time) * 1.25L); 208 | 209 | cout << " C library consistency test complete" << endl; 210 | } 211 | 212 | 213 | } // unnamed namespace 214 | 215 | //--------------------------------------------------------------------------------------// 216 | 217 | int cpp_main(int, char *[]) 218 | { 219 | cout << "---------- timer_test ----------\n"; 220 | 221 | unit_test(); 222 | format_test(); 223 | std_c_consistency_test(); 224 | 225 | return ::boost::report_errors(); 226 | } 227 | 228 | -------------------------------------------------------------------------------- /test/msvc10/chrono_dll/chrono_dll.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {C88697D9-587C-4649-AA39-8819A96A2A12} 15 | Win32Proj 16 | chrono_dll 17 | 10.0.16299.0 18 | 19 | 20 | 21 | DynamicLibrary 22 | true 23 | Unicode 24 | v141 25 | 26 | 27 | DynamicLibrary 28 | false 29 | true 30 | Unicode 31 | v141 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | Level3 56 | Disabled 57 | WIN32;_DEBUG;_WINDOWS;_USRDLL;CHRONO_DLL_EXPORTS;%(PreprocessorDefinitions) 58 | 59 | 60 | Windows 61 | true 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Level3 75 | 76 | 77 | MaxSpeed 78 | true 79 | true 80 | WIN32;NDEBUG;_WINDOWS;_USRDLL;CHRONO_DLL_EXPORTS;%(PreprocessorDefinitions) 81 | 82 | 83 | Windows 84 | true 85 | true 86 | true 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | {443dd1e8-4d52-4323-8280-a2320df7ef6d} 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /test/msvc10/common.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | ../../../../..;%(AdditionalIncludeDirectories) 9 | BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK;_UNICODE;UNICODE;%(PreprocessorDefinitions) 10 | Level4 11 | 12 | 13 | "$(TargetDir)\$(TargetName).exe" 14 | 15 | 16 | Executing test $(TargetName).exe... 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/msvc10/cpu_timer_test/cpu_timer_test.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {955C9C33-5364-4F02-9D59-65657E8DFBA9} 15 | Win32Proj 16 | cpu_timer_test 17 | 10.0.16299.0 18 | 19 | 20 | 21 | Application 22 | true 23 | Unicode 24 | v141 25 | 26 | 27 | Application 28 | false 29 | true 30 | Unicode 31 | v141 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | Disabled 56 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 57 | 58 | 59 | Console 60 | true 61 | 62 | 63 | 64 | 65 | Level3 66 | 67 | 68 | MaxSpeed 69 | true 70 | true 71 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 72 | 73 | 74 | Console 75 | true 76 | true 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | {c88697d9-587c-4649-aa39-8819a96a2a12} 86 | 87 | 88 | {443dd1e8-4d52-4323-8280-a2320df7ef6d} 89 | 90 | 91 | {8a6cf2a1-c5f7-4119-b510-88b98197bcb2} 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /test/msvc10/system_dll/system_dll.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D} 15 | Win32Proj 16 | system_dll 17 | 10.0.16299.0 18 | 19 | 20 | 21 | DynamicLibrary 22 | true 23 | Unicode 24 | v141 25 | 26 | 27 | DynamicLibrary 28 | false 29 | true 30 | Unicode 31 | v141 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | Level3 56 | Disabled 57 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SYSTEM_DLL_EXPORTS;%(PreprocessorDefinitions) 58 | 59 | 60 | Windows 61 | true 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Level3 75 | 76 | 77 | MaxSpeed 78 | true 79 | true 80 | WIN32;NDEBUG;_WINDOWS;_USRDLL;SYSTEM_DLL_EXPORTS;%(PreprocessorDefinitions) 81 | 82 | 83 | Windows 84 | true 85 | true 86 | true 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /test/msvc10/timer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C++ Express 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "timer_dll", "timer_dll\timer_dll.vcxproj", "{8A6CF2A1-C5F7-4119-B510-88B98197BCB2}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {C88697D9-587C-4649-AA39-8819A96A2A12} = {C88697D9-587C-4649-AA39-8819A96A2A12} 7 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D} = {443DD1E8-4D52-4323-8280-A2320DF7EF6D} 8 | EndProjectSection 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chrono_dll", "chrono_dll\chrono_dll.vcxproj", "{C88697D9-587C-4649-AA39-8819A96A2A12}" 11 | ProjectSection(ProjectDependencies) = postProject 12 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D} = {443DD1E8-4D52-4323-8280-A2320DF7EF6D} 13 | EndProjectSection 14 | EndProject 15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_dll", "system_dll\system_dll.vcxproj", "{443DD1E8-4D52-4323-8280-A2320DF7EF6D}" 16 | EndProject 17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpu_timer_test", "cpu_timer_test\cpu_timer_test.vcxproj", "{955C9C33-5364-4F02-9D59-65657E8DFBA9}" 18 | ProjectSection(ProjectDependencies) = postProject 19 | {8A6CF2A1-C5F7-4119-B510-88B98197BCB2} = {8A6CF2A1-C5F7-4119-B510-88B98197BCB2} 20 | {C88697D9-587C-4649-AA39-8819A96A2A12} = {C88697D9-587C-4649-AA39-8819A96A2A12} 21 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D} = {443DD1E8-4D52-4323-8280-A2320DF7EF6D} 22 | EndProjectSection 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Win32 = Debug|Win32 27 | Release|Win32 = Release|Win32 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Debug|Win32.ActiveCfg = Debug|Win32 31 | {8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Debug|Win32.Build.0 = Debug|Win32 32 | {8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Release|Win32.ActiveCfg = Release|Win32 33 | {8A6CF2A1-C5F7-4119-B510-88B98197BCB2}.Release|Win32.Build.0 = Release|Win32 34 | {C88697D9-587C-4649-AA39-8819A96A2A12}.Debug|Win32.ActiveCfg = Debug|Win32 35 | {C88697D9-587C-4649-AA39-8819A96A2A12}.Debug|Win32.Build.0 = Debug|Win32 36 | {C88697D9-587C-4649-AA39-8819A96A2A12}.Release|Win32.ActiveCfg = Release|Win32 37 | {C88697D9-587C-4649-AA39-8819A96A2A12}.Release|Win32.Build.0 = Release|Win32 38 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Debug|Win32.ActiveCfg = Debug|Win32 39 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Debug|Win32.Build.0 = Debug|Win32 40 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Release|Win32.ActiveCfg = Release|Win32 41 | {443DD1E8-4D52-4323-8280-A2320DF7EF6D}.Release|Win32.Build.0 = Release|Win32 42 | {955C9C33-5364-4F02-9D59-65657E8DFBA9}.Debug|Win32.ActiveCfg = Debug|Win32 43 | {955C9C33-5364-4F02-9D59-65657E8DFBA9}.Debug|Win32.Build.0 = Debug|Win32 44 | {955C9C33-5364-4F02-9D59-65657E8DFBA9}.Release|Win32.ActiveCfg = Release|Win32 45 | {955C9C33-5364-4F02-9D59-65657E8DFBA9}.Release|Win32.Build.0 = Release|Win32 46 | EndGlobalSection 47 | GlobalSection(SolutionProperties) = preSolution 48 | HideSolutionNode = FALSE 49 | EndGlobalSection 50 | EndGlobal 51 | -------------------------------------------------------------------------------- /test/msvc10/timer_dll/timer_dll.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {8A6CF2A1-C5F7-4119-B510-88B98197BCB2} 15 | Win32Proj 16 | timer_dll 17 | 10.0.16299.0 18 | 19 | 20 | 21 | DynamicLibrary 22 | true 23 | Unicode 24 | v141 25 | 26 | 27 | DynamicLibrary 28 | false 29 | true 30 | Unicode 31 | v141 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | Level3 56 | Disabled 57 | WIN32;_DEBUG;_WINDOWS;_USRDLL;TIMER_DLL_EXPORTS;%(PreprocessorDefinitions) 58 | 59 | 60 | Windows 61 | true 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Level3 75 | 76 | 77 | MaxSpeed 78 | true 79 | true 80 | WIN32;NDEBUG;_WINDOWS;_USRDLL;TIMER_DLL_EXPORTS;%(PreprocessorDefinitions) 81 | 82 | 83 | Windows 84 | true 85 | true 86 | true 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | {c88697d9-587c-4649-aa39-8819a96a2a12} 104 | 105 | 106 | {443dd1e8-4d52-4323-8280-a2320df7ef6d} 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /test/original_timer_test.cpp: -------------------------------------------------------------------------------- 1 | // timer, job_timer, and progress_display sample program -------------------// 2 | 3 | // Copyright Beman Dawes 1998. Distributed under the Boost 4 | // Software License, Version 1.0. (See accompanying file 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // See http://www.boost.org/libs/timer for documentation. 8 | 9 | // Revision History 10 | // 12 Jan 01 Cut time to 1.0 secs to speed regression tests (Beman Dawes) 11 | // 25 Sep 99 added elapsed_min() and elapsed_max() reporting 12 | // 16 Jul 99 Second beta 13 | // 6 Jul 99 Initial boost version 14 | 15 | #define BOOST_TIMER_ENABLE_DEPRECATED 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | using boost::timer; 22 | using boost::progress_timer; 23 | using boost::progress_display; 24 | using std::cout; 25 | using std::endl; 26 | 27 | int main() { 28 | 29 | timer t0; // used only for elapsed_max() and elapsed_min() 30 | 31 | cout << "timer::elapsed_min() reports " << t0.elapsed_min() << " seconds\n"; 32 | cout << "timer::elapsed_max() reports " << t0.elapsed_max() 33 | << " seconds, which is " << t0.elapsed_max()/3600.0 << " hours\n"; 34 | 35 | cout << "\nverify progress_display(0) doesn't divide by zero" << endl; 36 | progress_display zero( 0 ); // verify 0 doesn't divide by zero 37 | ++zero; 38 | 39 | long loops; 40 | timer loop_timer; 41 | const double time = 1.0; 42 | 43 | cout << "\ndetermine " << time << " second iteration count" << endl; 44 | for ( loops = 0; loops < LONG_MAX 45 | && loop_timer.elapsed() < time; ++loops ) {} 46 | cout << loops << " iterations"<< endl; 47 | 48 | long i; 49 | bool time_waster; // defeat [some] optimizers by storing result here 50 | 51 | progress_timer pt; 52 | timer t1; 53 | timer t4; 54 | timer t5; 55 | 56 | cout << "\nburn about " << time << " seconds" << endl; 57 | progress_display pd( loops ); 58 | for ( i = loops; i--; ) 59 | { time_waster = loop_timer.elapsed() < time; ++pd; } 60 | 61 | timer t2( t1 ); 62 | timer t3; 63 | t4 = t3; 64 | t5.restart(); 65 | 66 | cout << "\nburn about " << time << " seconds again" << endl; 67 | pd.restart( loops ); 68 | for ( i = loops; i--; ) 69 | { time_waster = loop_timer.elapsed() < time; ++pd; } 70 | 71 | if ( time_waster ) cout << ' '; // using time_waster quiets compiler warnings 72 | progress_display pd2( 50, cout, "\nLead string 1 ", "Lead string 2 ", "Lead string 3 " ); 73 | for ( ; pd2.count() < 50; ++pd2 ) {} 74 | 75 | cout << "\nt1 elapsed: " << t1.elapsed() << '\n'; 76 | cout << "t2 elapsed: " << t2.elapsed() << '\n'; 77 | cout << "t3 elapsed: " << t3.elapsed() << '\n'; 78 | cout << "t4 elapsed: " << t4.elapsed() << '\n'; 79 | cout << "t5 elapsed: " << t5.elapsed() << '\n'; 80 | cout << "t1 and t2 should report the same times (very approximately " 81 | << 2*time << " seconds).\n"; 82 | cout << "t3, t4 and t5 should report about the same times,\n"; 83 | cout << "and these should be about half the t1 and t2 times.\n"; 84 | cout << "The following elapsed time should be slightly greater than t1." 85 | << endl; 86 | return 0; 87 | } // main 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /test/progress_display_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2019 Peter Dimov. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() 11 | { 12 | int n = 17; 13 | 14 | std::ostringstream os; 15 | boost::timer::progress_display pd( n, os, "L1:", "L2:", "L3:" ); 16 | 17 | BOOST_TEST_EQ( os.str(), std::string( 18 | "L1:0% 10 20 30 40 50 60 70 80 90 100%\n" 19 | "L2:|----|----|----|----|----|----|----|----|----|----|\n" 20 | "L3:" ) ); 21 | 22 | for( int i = 0; i < n; ++i ) 23 | { 24 | std::size_t m1 = os.str().size(); 25 | ++pd; 26 | std::size_t m2 = os.str().size(); 27 | 28 | BOOST_TEST_LE( m1, m2 ); 29 | } 30 | 31 | BOOST_TEST_EQ( os.str(), std::string( 32 | "L1:0% 10 20 30 40 50 60 70 80 90 100%\n" 33 | "L2:|----|----|----|----|----|----|----|----|----|----|\n" 34 | "L3:***************************************************\n" ) ); 35 | 36 | return boost::report_errors(); 37 | } 38 | --------------------------------------------------------------------------------