mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
AK: Add benchmarks for floating point parsing
This commit is contained in:
parent
3c900765bc
commit
a179383dcc
Notes:
sideshowbarker
2024-07-18 03:23:00 +09:00
Author: https://github.com/DanShaders
Commit: a179383dcc
Pull-request: https://github.com/SerenityOS/serenity/pull/17398
Reviewed-by: https://github.com/davidot ✅
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
1 changed files with 30 additions and 0 deletions
|
@ -577,3 +577,33 @@ TEST_CASE(invalid_hex_floats)
|
|||
EXPECT_HEX_PARSE_TO_VALUE_AND_CONSUME_CHARS("0xABCDPEF", 0xabcdp0, 6);
|
||||
EXPECT_HEX_PARSE_TO_VALUE_AND_CONSUME_CHARS("0xCAPE", 0xCAp0, 4);
|
||||
}
|
||||
|
||||
#define BENCHMARK_DOUBLE_PARSING(value, iterations) \
|
||||
do { \
|
||||
auto data = #value##sv; \
|
||||
auto true_result = value; \
|
||||
for (int i = 0; i < iterations * 10'000; ++i) { \
|
||||
AK::taint_for_optimizer(data); \
|
||||
EXPECT_EQ(data.to_double(), true_result); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
BENCHMARK_CASE(one)
|
||||
{
|
||||
BENCHMARK_DOUBLE_PARSING(1, 500);
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(long_float_without_exponent)
|
||||
{
|
||||
BENCHMARK_DOUBLE_PARSING(1234567812345678, 400);
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(float_with_exponent)
|
||||
{
|
||||
BENCHMARK_DOUBLE_PARSING(1.234567e20, 400);
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(inadequate_float)
|
||||
{
|
||||
BENCHMARK_DOUBLE_PARSING(7.4109846876186981626485318930233205854758970392148714663837852375101326090531312779794975454245398856969484704316857659638998506553390969459816219401617281718945106978546710679176872575177347315553307795408549809608457500958111373034747658096871009590975442271004757307809711118935784838675653998783503015228055934046593739791790738723868299395818481660169122019456499931289798411362062484498678713572180352209017023903285791732520220528974020802906854021606612375549983402671300035812486479041385743401875520901590172592547146296175134159774938718574737870961645638908718119841271673056017045493004705269590165763776884908267986972573366521765567941072508764337560846003984904972149117463085539556354188641513168478436313080237596295773983001708984375001e-324, 4);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue