mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 21:45:20 +00:00
Userland/allocate: Switch to KiB/MiB
This commit is contained in:
parent
f47dbb6a58
commit
43a0ffe54d
Notes:
sideshowbarker
2024-07-19 03:34:31 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/43a0ffe54d4 Pull-request: https://github.com/SerenityOS/serenity/pull/3164 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/alimpfard
1 changed files with 19 additions and 17 deletions
|
@ -33,18 +33,20 @@
|
|||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("usage: allocate [number [unit (B/KB/MB)]]\n");
|
||||
printf("usage: allocate [number [unit (B/KiB/MiB)]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
enum class Unit { Bytes,
|
||||
KiloBytes,
|
||||
MegaBytes };
|
||||
enum class Unit {
|
||||
Bytes,
|
||||
KiB,
|
||||
MiB,
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int count = 50;
|
||||
auto unit = Unit::MegaBytes;
|
||||
auto unit = Unit::MiB;
|
||||
|
||||
if (argc >= 2) {
|
||||
auto number = String(argv[1]).to_uint();
|
||||
|
@ -57,10 +59,10 @@ int main(int argc, char** argv)
|
|||
if (argc >= 3) {
|
||||
if (strcmp(argv[2], "B") == 0)
|
||||
unit = Unit::Bytes;
|
||||
else if (strcmp(argv[2], "KB") == 0)
|
||||
unit = Unit::KiloBytes;
|
||||
else if (strcmp(argv[2], "MB") == 0)
|
||||
unit = Unit::MegaBytes;
|
||||
else if (strcmp(argv[2], "KiB") == 0)
|
||||
unit = Unit::KiB;
|
||||
else if (strcmp(argv[2], "MiB") == 0)
|
||||
unit = Unit::MiB;
|
||||
else
|
||||
usage();
|
||||
}
|
||||
|
@ -68,11 +70,11 @@ int main(int argc, char** argv)
|
|||
switch (unit) {
|
||||
case Unit::Bytes:
|
||||
break;
|
||||
case Unit::KiloBytes:
|
||||
count *= 1024;
|
||||
case Unit::KiB:
|
||||
count *= KiB;
|
||||
break;
|
||||
case Unit::MegaBytes:
|
||||
count *= 1024 * 1024;
|
||||
case Unit::MiB:
|
||||
count *= MiB;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -87,7 +89,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
printf("done in %dms\n", timer.elapsed());
|
||||
|
||||
auto pages = count / 4096;
|
||||
auto pages = count / PAGE_SIZE;
|
||||
auto step = pages / 10;
|
||||
|
||||
Core::ElapsedTimer timer2;
|
||||
|
@ -96,16 +98,16 @@ int main(int argc, char** argv)
|
|||
timer.start();
|
||||
timer2.start();
|
||||
for (int i = 0; i < pages; ++i) {
|
||||
ptr[i * 4096] = 1;
|
||||
ptr[i * PAGE_SIZE] = 1;
|
||||
|
||||
if (i != 0 && (i % step) == 0) {
|
||||
auto ms = timer2.elapsed();
|
||||
if (ms == 0)
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue