Created
April 1, 2020 02:34
-
-
Save terrelln/9bd53321a669f62683c608af8944fbc2 to your computer and use it in GitHub Desktop.
Measures the time it takes to decompress the linux kernel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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