Skip to content

Commit 20a6a6a

Browse files
committed
using dragonbox as the reference.
1 parent 6a4537a commit 20a6a6a

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.29)
1+
cmake_minimum_required(VERSION 3.28)
22

33
project(SimpleFastFloatBenchmark VERSION 0.1.0 LANGUAGES CXX C)
44
set(CMAKE_CXX_STANDARD 20)

benchmarks/exhaustivefloat32.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ void run_exhaustive32(bool errol) {
6868

6969
for (const auto &algo : args) {
7070
if (!algo.used) {
71-
std::cout << "# skipping " << algo.name << std::endl;
71+
fmt::print("# skipping {}\n", algo.name);
72+
continue;
73+
}
74+
if (algo.func == Benchmarks::dragonbox<float>) {
75+
fmt::print("# skipping {} because it is the reference.\n", algo.name);
7276
continue;
7377
}
7478
bool incorrect = false;
7579
char buf1[100], buf2[100];
7680
std::span<char> bufRef(buf1, sizeof(buf1)), bufAlgo(buf2, sizeof(buf2));
7781
fmt::print("# processing {}", algo.name);
7882
fflush(stdout);
79-
for(size_t i = 0; i < 1; i++) {
80-
//for (uint64_t i = 0; i < (1ULL << 32); ++i) {
83+
for (uint64_t i = 0; i < (1ULL << 32); ++i) {
8184
if (i % 0x2000000 == 0) {
8285
printf(".");
8386
fflush(stdout);
@@ -86,13 +89,13 @@ void run_exhaustive32(bool errol) {
8689
uint32_t i32(i);
8790
float d;
8891
std::memcpy(&d, &i32, sizeof(float));
89-
d = 33554448;
9092
if (std::isnan(d) || std::isinf(d))
9193
continue;
92-
// Reference output
93-
const size_t vRef = Benchmarks::std_to_chars(d, bufRef);
94-
d = 33554448;
95-
94+
// Reference output, we cannot use std::to_chars here, because it produces
95+
// the shortest representation, which is not necessarily the same as the
96+
// as the representation using the fewest significant digits.
97+
// So we use dragonbox, which serves as the reference implementation.
98+
const size_t vRef = Benchmarks::dragonbox(d, bufRef);
9699
const size_t vAlgo = algo.func(d, bufAlgo);
97100

98101
std::string_view svRef{bufRef.data(), vRef};
@@ -148,12 +151,12 @@ int main(int argc, char **argv) {
148151
const auto result = options.parse(argc, argv);
149152

150153
if (result["help"].as<bool>()) {
151-
std::cout << options.help() << std::endl;
154+
fmt::print("{}\n", options.help());
152155
return EXIT_SUCCESS;
153156
}
154157
run_exhaustive32(result["errol"].as<bool>());
155158
} catch (const std::exception &e) {
156-
std::cout << "error parsing options: " << e.what() << std::endl;
159+
fmt::print("error parsing options: {}\n", e.what());
157160
return EXIT_FAILURE;
158161
}
159162
}

0 commit comments

Comments
 (0)