mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
AK: Remove <chrono> requirement from TestSuite.h.
This commit is contained in:
parent
20a7d2c61b
commit
207b9774e0
1 changed files with 17 additions and 12 deletions
|
@ -42,25 +42,30 @@
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/NonnullRefPtrVector.h>
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <chrono>
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class TestElapsedTimer {
|
class TestElapsedTimer {
|
||||||
typedef std::chrono::high_resolution_clock clock;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestElapsedTimer() { restart(); }
|
TestElapsedTimer() { restart(); }
|
||||||
void restart() { m_started = clock::now(); }
|
|
||||||
int64_t elapsed()
|
void restart() { gettimeofday(&m_started, nullptr); }
|
||||||
|
|
||||||
|
u64 elapsed_milliseconds()
|
||||||
{
|
{
|
||||||
auto end = clock::now();
|
struct timeval now;
|
||||||
auto elapsed = end - m_started;
|
gettimeofday(&now, nullptr);
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
|
|
||||||
|
struct timeval delta;
|
||||||
|
timersub(&now, &m_started, &delta);
|
||||||
|
|
||||||
|
return delta.tv_sec * 1000 + delta.tv_usec / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::time_point<clock> m_started;
|
struct timeval m_started;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef AK::Function<void()> TestFunction;
|
typedef AK::Function<void()> TestFunction;
|
||||||
|
@ -182,7 +187,7 @@ void TestSuite::run(const NonnullRefPtrVector<TestCase>& tests)
|
||||||
dbg() << "START Running " << (t.is_benchmark() ? "benchmark" : "test") << " " << t.name();
|
dbg() << "START Running " << (t.is_benchmark() ? "benchmark" : "test") << " " << t.name();
|
||||||
TestElapsedTimer timer;
|
TestElapsedTimer timer;
|
||||||
t.func()();
|
t.func()();
|
||||||
auto time = timer.elapsed();
|
auto time = timer.elapsed_milliseconds();
|
||||||
fprintf(stderr, "\033[32;1mPASS\033[0m: %d ms running %s %s\n", (int)time, (t.is_benchmark() ? "benchmark" : "test"), t.name().characters());
|
fprintf(stderr, "\033[32;1mPASS\033[0m: %d ms running %s %s\n", (int)time, (t.is_benchmark() ? "benchmark" : "test"), t.name().characters());
|
||||||
if (t.is_benchmark()) {
|
if (t.is_benchmark()) {
|
||||||
m_benchtime += time;
|
m_benchtime += time;
|
||||||
|
@ -192,8 +197,8 @@ void TestSuite::run(const NonnullRefPtrVector<TestCase>& tests)
|
||||||
test_count++;
|
test_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg() << "Finished " << test_count << " tests and " << benchmark_count << " benchmarks in " << (int)global_timer.elapsed() << " ms ("
|
dbg() << "Finished " << test_count << " tests and " << benchmark_count << " benchmarks in " << (int)global_timer.elapsed_milliseconds() << " ms ("
|
||||||
<< (int)m_testtime << " tests, " << (int)m_benchtime << " benchmarks, " << int(global_timer.elapsed() - (m_testtime + m_benchtime)) << " other)";
|
<< (int)m_testtime << " tests, " << (int)m_benchtime << " benchmarks, " << int(global_timer.elapsed_milliseconds() - (m_testtime + m_benchtime)) << " other)";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue