Skip to content

Instantly share code, notes, and snippets.

@tnachen
Created October 6, 2014 18:29
Show Gist options
  • Save tnachen/50f3f376af9a0c158aa8 to your computer and use it in GitHub Desktop.
Save tnachen/50f3f376af9a0c158aa8 to your computer and use it in GitHub Desktop.
SVN Diff benchmark
struct Size {
int diff;
int orig;
Duration duration;
};
const int STEP = 16 * 1024;
static void benchDiff(int size, double diffPercent, bool silent)
{
vector<Size*> all;
for(int i = 0; i < size / STEP; ++i) {
Size* s = new Size();
all.push_back(s);
}
int tries = 50;
if (!silent) {
std::cout << "Benchmarking with max size: " << Bytes(size) << " and percent modified: "
<< stringify(diffPercent) << ", Averaging over " << stringify(tries) << " trials" << std::endl;
}
int current = 1;
while(current <= tries) {
int count = 0;
int currentSize = STEP;
while(currentSize <= size) {
string source;
while (Bytes(source.size()) < Bytes(currentSize)) {
source += (char) rand() % 256;
}
string target = source;
int maxOffset = currentSize / 2 + currentSize * diffPercent;
for(int i = currentSize / 2; i < maxOffset && i < currentSize; ++i) {
target[i] = (char) rand() % 256;
}
Stopwatch stopwatch;
stopwatch.start();
Try<svn::Diff> diff = svn::diff(source, target);
stopwatch.stop();
ASSERT_SOME(diff);
Size* s = all[count];
s->diff = diff.get().data.size();
s->orig = currentSize;
if (current == 1) {
s->duration = stopwatch.elapsed();
} else {
s->duration += stopwatch.elapsed();
}
currentSize += STEP;
count++;
}
current++;
}
if (!silent) {
foreach(Size* size, all) {
// 2.119 is the amount of nano seconds it takes to write a byte
// into a SSD, assuming 450 mb / second.
// 0.5 is the amount of nano seconds to write a byte over
// the network (2000 bytes takes 1000 ns).
int cost = (size->duration.ns() / tries) + (size->diff * 2.119) + (size->diff * 0.5);
std::cout << cost << std::endl;
delete size;
}
}
}
TEST(SVN, DiffPatch)
{
benchDiff(1024 * 8, 0.1, true);
for (double i = 0.1; i <= 0.3; i += 0.05) {
benchDiff(1024 * 1024, i, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment