1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:27:45 +00:00

Userland: Replace most printf-style APIs with AK::Format APIs :^)

This commit is contained in:
Linus Groh 2021-05-31 15:43:25 +01:00
parent 4f1889c2cb
commit f5c35fccca
75 changed files with 642 additions and 644 deletions

View file

@ -7,13 +7,12 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibCore/ElapsedTimer.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static void usage()
{
printf("usage: allocate [number [unit (B/KiB/MiB)]]\n");
warnln("usage: allocate [number [unit (B/KiB/MiB)]]");
exit(1);
}
@ -60,21 +59,21 @@ int main(int argc, char** argv)
Core::ElapsedTimer timer;
printf("allocating memory (%d bytes)...\n", count);
outln("allocating memory ({} bytes)...", count);
timer.start();
char* ptr = (char*)malloc(count);
if (!ptr) {
printf("failed.\n");
outln("failed.");
return 1;
}
printf("done in %dms\n", timer.elapsed());
outln("done in {}ms", timer.elapsed());
auto pages = count / PAGE_SIZE;
auto step = pages / 10;
Core::ElapsedTimer timer2;
printf("writing one byte to each page of allocated memory...\n");
outln("writing one byte to each page of allocated memory...");
timer.start();
timer2.start();
for (int i = 0; i < pages; ++i) {
@ -87,24 +86,24 @@ int main(int argc, char** argv)
auto bps = double(step * PAGE_SIZE) / (double(ms) / 1000);
printf("step took %dms (%fMiB/s)\n", ms, bps / MiB);
outln("step took {}ms ({}MiB/s)", ms, bps / MiB);
timer2.start();
}
}
printf("done in %dms\n", timer.elapsed());
outln("done in {}ms", timer.elapsed());
printf("sleeping for ten seconds...\n");
outln("sleeping for ten seconds...");
for (int i = 0; i < 10; i++) {
printf("%d\n", i);
outln("{}", i);
sleep(1);
}
printf("done.\n");
outln("done.");
printf("freeing memory...\n");
outln("freeing memory...");
timer.start();
free(ptr);
printf("done in %dms\n", timer.elapsed());
outln("done in {}ms", timer.elapsed());
return 0;
}