Skip to content
Snippets Groups Projects
Commit a4cc5a07 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Add time_to_spawn evaluation

parent fbfa8889
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,8 @@ add_subdirectory("apps")
add_subdirectory("tests")
add_subdirectory("eval")
file(GLOB ALL_SOURCE_FILES *.cpp)
file(GLOB ALL_HEADER_FILES *.hpp)
......
add_executable(time_to_spawn TimeToSpawn.cpp)
target_link_libraries(time_to_spawn Threads::Threads emper)
#include "Runtime.hpp"
#include "BinaryPrivateSemaphore.hpp"
#include <chrono>
#include <thread>
#include <mutex>
static std::chrono::nanoseconds threadTimeToSpawn() {
std::chrono::time_point<std::chrono::high_resolution_clock> end;
auto start = std::chrono::high_resolution_clock::now();
std::thread t([&end] {
end = std::chrono::high_resolution_clock::now();
});
t.join();
return std::chrono::duration_cast<std::chrono::nanoseconds>(end - start);
}
static std::chrono::nanoseconds fiberTimeToSpawn() {
std::chrono::nanoseconds res;
Runtime runtime;
std::mutex testFinished;
testFinished.lock();
Fiber* fiber = Fiber::from([&runtime, &res, &testFinished] {
BPS bps;
std::chrono::time_point<std::chrono::high_resolution_clock> end;
Fiber* fiber = Fiber::from([&end, &bps] {
end = std::chrono::high_resolution_clock::now();
bps.signal();
});
auto start = std::chrono::high_resolution_clock::now();
runtime.schedule(*fiber);
bps.wait();
res = std::chrono::duration_cast<std::chrono::nanoseconds>(end -start);
testFinished.unlock();
});
runtime.schedule(*fiber);
testFinished.lock();
// The destructor of Runtime causes all runtime threads to terminate.
return res;
}
int main(UNUSED_ARG int argc, UNUSED_ARG char *argv[]) {
{
auto ttts = threadTimeToSpawn();
std::cout << "Thread time to spawn: "
<< ttts.count() << "us"
<< std::endl;
}
{
auto ftts = fiberTimeToSpawn();
std::cout << "Fiber time to spawn: "
<< ftts.count() << "us"
<< std::endl;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment