Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 99 | pmbaty | 1 | /* |
| 2 | Texel - A UCI chess engine. |
||
| 3 | Copyright (C) 2013-2014 Peter Ă–sterlund, peterosterlund2@gmail.com |
||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify |
||
| 6 | it under the terms of the GNU General Public License as published by |
||
| 7 | the Free Software Foundation, either version 3 of the License, or |
||
| 8 | (at your option) any later version. |
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, |
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | GNU General Public License for more details. |
||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License |
||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 17 | */ |
||
| 18 | |||
| 19 | /* |
||
| 20 | * timeUtil.cpp |
||
| 21 | * |
||
| 22 | * Created on: Sep 20, 2013 |
||
| 23 | * Author: petero |
||
| 24 | */ |
||
| 25 | |||
| 26 | #include "timeUtil.hpp" |
||
| 27 | |||
| 28 | #include <chrono> |
||
| 29 | #include <iostream> |
||
| 30 | |||
| 31 | #ifdef HAS_RT |
||
| 32 | #include <time.h> |
||
| 33 | #include <sys/time.h> |
||
| 34 | #endif |
||
| 35 | |||
| 36 | S64 currentTimeMillis() { |
||
| 37 | #ifdef HAS_RT |
||
| 38 | clockid_t c = CLOCK_MONOTONIC; |
||
| 39 | timespec sp; |
||
| 40 | clock_gettime(c, &sp); |
||
| 41 | return (S64)(sp.tv_sec * 1e3 + sp.tv_nsec * 1e-6); |
||
| 42 | #else |
||
| 43 | auto t = std::chrono::high_resolution_clock::now(); |
||
| 44 | auto t0 = t.time_since_epoch(); |
||
| 45 | auto x = t0.count(); |
||
| 46 | using T0Type = decltype(t0); |
||
| 47 | auto n = T0Type::period::num; |
||
| 48 | auto d = T0Type::period::den; |
||
| 49 | return (S64)(x * (1000.0 * n / d)); |
||
| 50 | #endif |
||
| 51 | } |
||
| 52 | |||
| 53 | double currentTime() { |
||
| 54 | #ifdef HAS_RT |
||
| 55 | clockid_t c = CLOCK_MONOTONIC; |
||
| 56 | timespec sp; |
||
| 57 | clock_gettime(c, &sp); |
||
| 58 | return sp.tv_sec + sp.tv_nsec * 1e-9; |
||
| 59 | #else |
||
| 60 | auto t = std::chrono::high_resolution_clock::now(); |
||
| 61 | auto t0 = t.time_since_epoch(); |
||
| 62 | double x = (double)t0.count(); // Pierre-Marie Baty -- added type cast |
||
| 63 | using T0Type = decltype(t0); |
||
| 64 | double n = T0Type::period::num; |
||
| 65 | double d = T0Type::period::den; |
||
| 66 | return x * n / d; |
||
| 67 | #endif |
||
| 68 | } |
||
| 69 | |||
| 70 | SampleStatistics& |
||
| 71 | SampleStatistics::operator+=(const SampleStatistics& other) { |
||
| 72 | nSamples += other.nSamples; |
||
| 73 | sum += other.sum; |
||
| 74 | sqSum += other.sqSum; |
||
| 75 | return *this; |
||
| 76 | } |