mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 02:09:24 +00:00
AK: Make String::number() much faster for integer types
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Instead of going through String::formatted(), we now have a specialized code path for base-10 serialization directly to UTF-8. This is roughly 5-10x faster than the previous implementation, depending on how many digits we end up outputting. 1.07x speedup on MicroBench/for-in-indexed-properties.js
This commit is contained in:
parent
4d84e1a8bc
commit
cf6e2531d9
Notes:
github-actions[bot]
2025-05-02 17:13:56 +00:00
Author: https://github.com/awesomekling
Commit: cf6e2531d9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4553
3 changed files with 99 additions and 1 deletions
|
@ -1561,3 +1561,45 @@ TEST_CASE(roman_numerals)
|
|||
auto four_thousand = String::roman_number_from(4000, String::Case::Upper);
|
||||
EXPECT_EQ(four_thousand, "4000"sv);
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(string_number_u16)
|
||||
{
|
||||
for (size_t i = 0; i < 10'000'000; ++i) {
|
||||
(void)String::number(static_cast<u16>(12345));
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(string_number_u32)
|
||||
{
|
||||
for (size_t i = 0; i < 10'000'000; ++i) {
|
||||
(void)String::number(static_cast<u32>(123456789));
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(string_number_u64)
|
||||
{
|
||||
for (size_t i = 0; i < 10'000'000; ++i) {
|
||||
(void)String::number(static_cast<u64>(123456789));
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(string_number_i16)
|
||||
{
|
||||
for (size_t i = 0; i < 10'000'000; ++i) {
|
||||
(void)String::number(static_cast<i16>(-12345));
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(string_number_i32)
|
||||
{
|
||||
for (size_t i = 0; i < 10'000'000; ++i) {
|
||||
(void)String::number(static_cast<i32>(-123456789));
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(string_number_i64)
|
||||
{
|
||||
for (size_t i = 0; i < 10'000'000; ++i) {
|
||||
(void)String::number(static_cast<i64>(-123456789));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue