Skip to content

Instantly share code, notes, and snippets.

@terrelln
Created April 1, 2020 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrelln/9bd53321a669f62683c608af8944fbc2 to your computer and use it in GitHub Desktop.
Save terrelln/9bd53321a669f62683c608af8944fbc2 to your computer and use it in GitHub Desktop.
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