|
| 1 | +/* |
| 2 | + Copyright 2018-2023 Tatsuya Yamasaki. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#ifndef INCLUDED_MEEVAX_CHRONO_DURATION_HPP |
| 18 | +#define INCLUDED_MEEVAX_CHRONO_DURATION_HPP |
| 19 | + |
| 20 | +#include <chrono> |
| 21 | +#include <iostream> |
| 22 | + |
| 23 | +namespace meevax |
| 24 | +{ |
| 25 | +inline namespace chrono |
| 26 | +{ |
| 27 | + using days = std::chrono::duration<std::size_t, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>; |
| 28 | + |
| 29 | + using years = std::chrono::duration<std::size_t, std::ratio_multiply<std::ratio<146097, 400>, days::period>>; |
| 30 | + |
| 31 | + using months = std::chrono::duration<std::size_t, std::ratio_divide<years::period, std::ratio<12>>>; |
| 32 | + |
| 33 | + template <typename Thunk> |
| 34 | + auto duration(Thunk thunk) |
| 35 | + { |
| 36 | + auto begin = std::chrono::high_resolution_clock::now(); |
| 37 | + thunk(); |
| 38 | + return std::chrono::high_resolution_clock::now() - begin; |
| 39 | + } |
| 40 | + |
| 41 | + auto operator <<(std::ostream &, std::chrono::nanoseconds) -> std::ostream &; |
| 42 | +} // namespace chrono |
| 43 | +} // namespace meevax |
| 44 | + |
| 45 | +#endif // INCLUDED_MEEVAX_CHRONO_DURATION_HPP |
0 commit comments