Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Measures the time it takes to decompress the linux kernel
#include <chrono>
#include <stdio.h>
namespace {
void wait_for_needle(char const* needle) {
char const* suffix = needle;
while (*suffix != '\0') {
auto const c = getc(stdin);
if (c == *suffix) {
++suffix;
} else {
suffix = needle;
}
}
}
void wait_for_start() {
wait_for_needle("Decompressing Linux...");
}
void wait_for_end() {
wait_for_needle("Parsing ELF");
}
}
int main() {
wait_for_start();
auto begin = std::chrono::steady_clock::now();
wait_for_end();
auto end = std::chrono::steady_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
fprintf(stdout, "time = %u ms\n", (unsigned)(dur.count()));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.