1 // 2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 // Official repository: https://github.com/boostorg/beast 8 // 9 10 #ifndef BOOST_BEAST_TEST_THROUGHPUT_HPP 11 #define BOOST_BEAST_TEST_THROUGHPUT_HPP 12 13 #include <chrono> 14 #include <cstdint> 15 16 namespace boost { 17 namespace beast { 18 namespace test { 19 20 class timer 21 { 22 using clock_type = 23 std::chrono::system_clock; 24 25 clock_type::time_point when_; 26 27 public: 28 using duration = 29 clock_type::duration; 30 timer()31 timer() 32 : when_(clock_type::now()) 33 { 34 } 35 36 duration elapsed() const37 elapsed() const 38 { 39 return clock_type::now() - when_; 40 } 41 }; 42 43 inline 44 std::uint64_t throughput(std::chrono::duration<double> const & elapsed,std::uint64_t items)45throughput(std::chrono::duration< 46 double> const& elapsed, std::uint64_t items) 47 { 48 using namespace std::chrono; 49 return static_cast<std::uint64_t>( 50 1 / (elapsed/items).count()); 51 } 52 53 } // test 54 } // beast 55 } // boost 56 57 #endif 58