timer-test.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // base/timer-test.cc
  2. // Copyright 2009-2011 Microsoft Corporation
  3. // 2014 Johns Hopkins University (author: Daniel Povey)
  4. // See ../../COPYING for clarification regarding multiple authors
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  11. // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  12. // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  13. // MERCHANTABLITY OR NON-INFRINGEMENT.
  14. // See the Apache 2 License for the specific language governing permissions and
  15. // limitations under the License.
  16. #include "base/timer.h"
  17. #include "base/kaldi-common.h"
  18. #include "base/kaldi-utils.h"
  19. namespace kaldi {
  20. void TimerTest() {
  21. float time_secs = 0.025 * (rand() % 10);
  22. std::cout << "target is " << time_secs << "\n";
  23. Timer timer;
  24. Sleep(time_secs);
  25. BaseFloat f = timer.Elapsed();
  26. std::cout << "time is " << f << std::endl;
  27. if (fabs(time_secs - f) > 0.05)
  28. KALDI_ERR << "Timer fail: waited " << f << " seconds instead of "
  29. << time_secs << " secs.";
  30. }
  31. }
  32. int main() {
  33. for (int i = 0; i < 4; i++)
  34. kaldi::TimerTest();
  35. }