Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: third_party/google_benchmark/src/sleep.cc

Issue 2865663003: Adding Google benchmarking library. (Closed)
Patch Set: Sketch. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/google_benchmark/src/sleep.h ('k') | third_party/google_benchmark/src/stat.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "sleep.h"
16
17 #include <cerrno>
18 #include <cstdlib>
19 #include <ctime>
20
21 #include "internal_macros.h"
22
23 #ifdef BENCHMARK_OS_WINDOWS
24 #include <Windows.h>
25 #endif
26
27 namespace benchmark {
28 #ifdef BENCHMARK_OS_WINDOWS
29 // Window's Sleep takes milliseconds argument.
30 void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); }
31 void SleepForSeconds(double seconds) {
32 SleepForMilliseconds(static_cast<int>(kNumMillisPerSecond * seconds));
33 }
34 #else // BENCHMARK_OS_WINDOWS
35 void SleepForMicroseconds(int microseconds) {
36 struct timespec sleep_time;
37 sleep_time.tv_sec = microseconds / kNumMicrosPerSecond;
38 sleep_time.tv_nsec = (microseconds % kNumMicrosPerSecond) * kNumNanosPerMicro;
39 while (nanosleep(&sleep_time, &sleep_time) != 0 && errno == EINTR)
40 ; // Ignore signals and wait for the full interval to elapse.
41 }
42
43 void SleepForMilliseconds(int milliseconds) {
44 SleepForMicroseconds(milliseconds * kNumMicrosPerMilli);
45 }
46
47 void SleepForSeconds(double seconds) {
48 SleepForMicroseconds(static_cast<int>(seconds * kNumMicrosPerSecond));
49 }
50 #endif // BENCHMARK_OS_WINDOWS
51 } // end namespace benchmark
OLDNEW
« no previous file with comments | « third_party/google_benchmark/src/sleep.h ('k') | third_party/google_benchmark/src/stat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698