Skip to content

Instantly share code, notes, and snippets.

@vegard

vegard/input.cc Secret

Created September 30, 2018 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vegard/e79b96cefffbfb753da17c4646132fab to your computer and use it in GitHub Desktop.
Save vegard/e79b96cefffbfb753da17c4646132fab to your computer and use it in GitHub Desktop.
creduce vs. halfempty benchmark
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <set>
#include <vector>
#if 1
typedef std::vector<int> int_vector;
#else
typedef std::vector<long int> int_vector;
#endif
struct foobar {
std::set<int_vector> x;
foobar()
{
int_vector v;
v.push_back(123);
v.push_back(678);
x.insert(v);
}
};
struct baz {
std::set<int_vector> x;
baz()
{
}
int dummy()
{
return 123456678;
}
};
int get_it(foobar *f)
{
auto &s = f->x;
const int_vector &v = *s.begin();
return v[0];
}
int main(int argc, char *argv[])
{
foobar fb;
printf("This is the output: %d\n", get_it(&fb));
return 0;
}
void dummy()
{
printf("Hello world!\n");
}
struct unused {
int xyz;
};
#include <set>
#include <stdio.h>
#include <vector>
#if 1
typedef std::vector<int> a;
#endif
struct b {
std::set<a> c;
b() {
a d;
d.push_back(123);
c.insert(d);
}
};
int e(b *f) {
auto g = f->c;
a d = *g.begin();
return d[0];
}
main() {
b fb;
printf("This is the output: %d\n", e(&fb));
}
#include<fcntl.h>
#include<string>
#include<set>
#include<vector>
#if1
typedefstd::vector<int>int_vector;
#else
#endif
structfoobar{std::set<int_vector>x;foobar(){int_vectorv;v.push_back(123);x.insert(v);}};structz{std::set<int_vector>x;inty(){return4;}};intget_it(foobar*f){autos=f->x;constint_vectorv=*s.begin();returnv[0];}main(int,char){foobarfb;printf("This is the output: %d",get_it(&fb));}voidy(){printf("");}structu{intz;};
#! /bin/bash
cp input.cc creduce-input.cc
#time env REDUCE_INPUT=creduce-input.cc ~/creduce/creduce/creduce --n 32 test.sh creduce-input.cc
time env REDUCE_INPUT=creduce-input.cc ~/creduce/creduce/creduce --n 1 test.sh creduce-input.cc
#! /bin/bash
ulimit -n 1048576
cp input.cc halfempty-input.cc
#time env REDUCE_INPUT=/dev/stdin ~/halfempty/halfempty --num-threads=32 --cleanup-threads=1 test.sh halfempty-input.cc
time env REDUCE_INPUT=/dev/stdin ~/halfempty/halfempty --num-threads=1 --cleanup-threads=1 test.sh halfempty-input.cc
#! /bin/bash
set -e
set -u
tmpdir="$(mktemp -d)"
cat ${REDUCE_INPUT} > $tmpdir/input.cc
g++ -std=c++14 -o $tmpdir/output $tmpdir/input.cc
result="$(timeout 1s $tmpdir/output)"
rm -rf "$tmpdir"
[[ "$result" == "This is the output: 123" ]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment