[PATCH] D54383: [llvm-exegesis] Analysis: writeMeasurementValue(): don't alloc string for double each time.
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 19 05:31:13 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347199: [llvm-exegesis] Analysis: writeMeasurementValue(): don't alloc string for… (authored by lebedevri, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D54383?vs=173650&id=174594#toc
Repository:
rL LLVM
https://reviews.llvm.org/D54383
Files:
llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
Index: llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
===================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/FormatVariadic.h"
+#include <limits>
#include <unordered_set>
#include <vector>
@@ -95,7 +96,21 @@
template <EscapeTag Tag>
static void writeMeasurementValue(llvm::raw_ostream &OS, const double Value) {
- writeEscaped<Tag>(OS, llvm::formatv("{0:F}", Value).str());
+ // Given Value, if we wanted to serialize it to a string,
+ // how many base-10 digits will we need to store, max?
+ static constexpr auto MaxDigitCount =
+ std::numeric_limits<decltype(Value)>::max_digits10;
+ // Also, we will need a decimal separator.
+ static constexpr auto DecimalSeparatorLen = 1; // '.' e.g.
+ // So how long of a string will the serialization produce, max?
+ static constexpr auto SerializationLen = MaxDigitCount + DecimalSeparatorLen;
+
+ // WARNING: when changing the format, also adjust the small-size estimate ^.
+ static constexpr StringLiteral SimpleFloatFormat = StringLiteral("{0:F}");
+
+ writeEscaped<Tag>(
+ OS,
+ llvm::formatv(SimpleFloatFormat.data(), Value).sstr<SerializationLen>());
}
template <typename EscapeTag, EscapeTag Tag>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54383.174594.patch
Type: text/x-patch
Size: 1410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181119/a8c9da7c/attachment.bin>
More information about the llvm-commits
mailing list