Commit 4dd3161d authored by Kenton Varda's avatar Kenton Varda

Benchmark improvements.

parent eb710512
...@@ -96,25 +96,28 @@ struct Packed { ...@@ -96,25 +96,28 @@ struct Packed {
} }
}; };
static byte snappyReadBuffer[SNAPPY_BUFFER_SIZE];
static byte snappyWriteBuffer[SNAPPY_BUFFER_SIZE];
static byte snappyCompressedBuffer[SNAPPY_COMPRESSED_BUFFER_SIZE];
struct SnappyCompressed { struct SnappyCompressed {
typedef FdInputStream& BufferedInput; typedef BufferedInputStreamWrapper BufferedInput;
typedef SnappyMessageReader MessageReader; typedef SnappyPackedMessageReader MessageReader;
class ArrayMessageReader: private ArrayInputStream, public SnappyMessageReader { class ArrayMessageReader: private ArrayInputStream, public SnappyPackedMessageReader {
public: public:
ArrayMessageReader(ArrayPtr<const byte> array, ArrayMessageReader(ArrayPtr<const byte> array,
ReaderOptions options = ReaderOptions(), ReaderOptions options = ReaderOptions(),
ArrayPtr<word> scratchSpace = nullptr) ArrayPtr<word> scratchSpace = nullptr)
: ArrayInputStream(array), : ArrayInputStream(array),
SnappyMessageReader(*this, options, scratchSpace) {} SnappyPackedMessageReader(static_cast<ArrayInputStream&>(*this), options, scratchSpace,
arrayPtr(snappyReadBuffer, SNAPPY_BUFFER_SIZE)) {}
}; };
static inline void write(OutputStream& output, MessageBuilder& builder) { static inline void write(OutputStream& output, MessageBuilder& builder) {
writeSnappyMessage(output, builder); writeSnappyPackedMessage(output, builder,
} arrayPtr(snappyWriteBuffer, SNAPPY_BUFFER_SIZE),
arrayPtr(snappyCompressedBuffer, SNAPPY_COMPRESSED_BUFFER_SIZE));
static inline void write(BufferedOutputStream& output, MessageBuilder& builder) {
writeSnappyMessage(output, builder);
} }
}; };
......
...@@ -278,11 +278,11 @@ void reportComparisonHeader() { ...@@ -278,11 +278,11 @@ void reportComparisonHeader() {
class Gain { class Gain {
public: public:
Gain(double oldValue, double newValue) Gain(double oldValue, double newValue)
: amount(oldValue < newValue ? newValue / oldValue : -oldValue / newValue) {} : amount(newValue / oldValue) {}
void writeTo(std::ostream& os) { void writeTo(std::ostream& os) {
if (-2 < amount && amount < 2) { if (amount < 2) {
double percent = (amount > 0 ? amount - 1 : amount + 1) * 100; double percent = (amount - 1) * 100;
os << (int)(percent + 0.5) << "%"; os << (int)(percent + 0.5) << "%";
} else { } else {
os << fixed << setprecision(2) << amount << "x"; os << fixed << setprecision(2) << amount << "x";
...@@ -311,8 +311,18 @@ void reportComparison(const char* name, double base, double protobuf, double cap ...@@ -311,8 +311,18 @@ void reportComparison(const char* name, double base, double protobuf, double cap
void reportComparison(const char* name, const char* unit, double protobuf, double capnproto, void reportComparison(const char* name, const char* unit, double protobuf, double capnproto,
uint64_t iters) { uint64_t iters) {
cout << setw(35) << left << name cout << setw(35) << left << name
<< setw(15-strlen(unit)) << right << setprecision(2) << (protobuf / iters) << unit << setw(15-strlen(unit)) << fixed << right << setprecision(2) << (protobuf / iters) << unit
<< setw(15-strlen(unit)) << right << setprecision(2) << (capnproto / iters) << unit; << setw(15-strlen(unit)) << fixed << right << setprecision(2) << (capnproto / iters) << unit;
// Since smaller is better, the "improvement" is the "gain" from capnproto to protobuf.
cout << setw(14) << right << Gain(capnproto, protobuf) << endl;
}
void reportIntComparison(const char* name, const char* unit, uint64_t protobuf, uint64_t capnproto,
uint64_t iters) {
cout << setw(35) << left << name
<< setw(15-strlen(unit)) << right << (protobuf / iters) << unit
<< setw(15-strlen(unit)) << right << (capnproto / iters) << unit;
// Since smaller is better, the "improvement" is the "gain" from capnproto to protobuf. // Since smaller is better, the "improvement" is the "gain" from capnproto to protobuf.
cout << setw(14) << right << Gain(capnproto, protobuf) << endl; cout << setw(14) << right << Gain(capnproto, protobuf) << endl;
...@@ -472,7 +482,7 @@ int main(int argc, char* argv[]) { ...@@ -472,7 +482,7 @@ int main(int argc, char* argv[]) {
((int64_t)protobuf.time.cpu() - (int64_t)protobufBase.time.cpu()) / 1000.0, ((int64_t)protobuf.time.cpu() - (int64_t)protobufBase.time.cpu()) / 1000.0,
((int64_t)capnp.time.cpu() - (int64_t)capnpBase.time.cpu()) / 1000.0, iters); ((int64_t)capnp.time.cpu() - (int64_t)capnpBase.time.cpu()) / 1000.0, iters);
reportComparison("bandwidth", "B", protobuf.throughput, capnp.throughput, iters); reportIntComparison("bandwidth", "B", protobuf.throughput, capnp.throughput, iters);
reportComparison("binary size", "kB", reportComparison("binary size", "kB",
fileSize("protobuf-" + std::string(testCaseName(testCase))) / 1024.0, fileSize("protobuf-" + std::string(testCaseName(testCase))) / 1024.0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment