1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-12 02:30:30 +09:00

Userland/allocate: Switch to KiB/MiB

This commit is contained in:
Nico Weber 2020-08-15 14:28:15 -04:00 committed by Andreas Kling
parent f47dbb6a58
commit 43a0ffe54d
Notes: sideshowbarker 2024-07-19 03:34:31 +09:00

View file

@ -33,18 +33,20 @@
static void usage(void) static void usage(void)
{ {
printf("usage: allocate [number [unit (B/KB/MB)]]\n"); printf("usage: allocate [number [unit (B/KiB/MiB)]]\n");
exit(1); exit(1);
} }
enum class Unit { Bytes, enum class Unit {
KiloBytes, Bytes,
MegaBytes }; KiB,
MiB,
};
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int count = 50; int count = 50;
auto unit = Unit::MegaBytes; auto unit = Unit::MiB;
if (argc >= 2) { if (argc >= 2) {
auto number = String(argv[1]).to_uint(); auto number = String(argv[1]).to_uint();
@ -57,10 +59,10 @@ int main(int argc, char** argv)
if (argc >= 3) { if (argc >= 3) {
if (strcmp(argv[2], "B") == 0) if (strcmp(argv[2], "B") == 0)
unit = Unit::Bytes; unit = Unit::Bytes;
else if (strcmp(argv[2], "KB") == 0) else if (strcmp(argv[2], "KiB") == 0)
unit = Unit::KiloBytes; unit = Unit::KiB;
else if (strcmp(argv[2], "MB") == 0) else if (strcmp(argv[2], "MiB") == 0)
unit = Unit::MegaBytes; unit = Unit::MiB;
else else
usage(); usage();
} }
@ -68,11 +70,11 @@ int main(int argc, char** argv)
switch (unit) { switch (unit) {
case Unit::Bytes: case Unit::Bytes:
break; break;
case Unit::KiloBytes: case Unit::KiB:
count *= 1024; count *= KiB;
break; break;
case Unit::MegaBytes: case Unit::MiB:
count *= 1024 * 1024; count *= MiB;
break; break;
} }
@ -87,7 +89,7 @@ int main(int argc, char** argv)
} }
printf("done in %dms\n", timer.elapsed()); printf("done in %dms\n", timer.elapsed());
auto pages = count / 4096; auto pages = count / PAGE_SIZE;
auto step = pages / 10; auto step = pages / 10;
Core::ElapsedTimer timer2; Core::ElapsedTimer timer2;
@ -96,16 +98,16 @@ int main(int argc, char** argv)
timer.start(); timer.start();
timer2.start(); timer2.start();
for (int i = 0; i < pages; ++i) { for (int i = 0; i < pages; ++i) {
ptr[i * 4096] = 1; ptr[i * PAGE_SIZE] = 1;
if (i != 0 && (i % step) == 0) { if (i != 0 && (i % step) == 0) {
auto ms = timer2.elapsed(); auto ms = timer2.elapsed();
if (ms == 0) if (ms == 0)
ms = 1; ms = 1;
auto bps = double(step * 4096) / (double(ms) / 1000); auto bps = double(step * PAGE_SIZE) / (double(ms) / 1000);
printf("step took %dms (%fMB/s)\n", ms, bps / 1024 / 1024); printf("step took %dms (%fMiB/s)\n", ms, bps / MiB);
timer2.start(); timer2.start();
} }