本文整理汇总了C++中Benchmark类的典型用法代码示例。如果您正苦于以下问题:C++ Benchmark类的具体用法?C++ Benchmark怎么用?C++ Benchmark使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Benchmark类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[])
{
string data_file;
string benchmark;
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message.")
("data,D", po::value<string>(&data_file), "data file")
("benchmark,B", po::value<string>(&benchmark), "benchmark file")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
FloatMatrix data(data_file);
Benchmark<> bench;
bench.load(benchmark);
for (unsigned i = 0; i < bench.getQ(); ++i) {
const float *p = data[bench.getQuery(i)];
cout << p[0];
for (int d = 1; d < data.getDim(); ++d) {
cout << ' ' << p[d];
}
cout << endl;
}
return 0;
}
示例2: TEST_F
TEST_F(BenchmarkTest, it_measures_time_consuming) {
Benchmark benchmark;
benchmark.start();
int time_to_sleep = 1;
suspend(time_to_sleep);
ASSERT_TRUE(time_to_sleep <= benchmark.end());
}
示例3: main
/** \brief Główna funkcja programu
*
* Pozwala na zmierzenie czasu dla poszczególnych implementacji tablicy asocjacyjnej na różnych strukturach danych.
*/
int main(int argc, char **argv) {
srand(time(NULL));
if (argc < 4 )
{ cerr << "Zbyt mala ilosc argumentow." << endl;
return 0;
}
Benchmark timeCount;
string whichType=argv[1];
sType make;
if (whichType == "aarray") make = aarray;
else if (whichType == "hash") make = hash;
else if (whichType == "tree") make = tree;
else { cerr << "Wybrano nieprawidłową strukturę." << endl;
return 0;}
int problemSize = atoi(argv[2]);
int noIterations = atoi(argv[3]);
double time = timeCount.benchmark(noIterations, make, problemSize);
cout << problemSize << "," << noIterations << "," << time << endl;
}
示例4: main
int main(const int argc, const char *argv[]) {
using namespace Slic3r;
using std::cout; using std::endl;
if(argc < 2) {
cout << USAGE_STR << endl;
return EXIT_SUCCESS;
}
TriangleMesh model;
Benchmark bench;
model.ReadSTLFile(argv[1]);
model.align_to_origin();
ExPolygons ground_slice;
TriangleMesh basepool;
sla::base_plate(model, ground_slice, 0.1f);
bench.start();
sla::create_base_pool(ground_slice, basepool);
bench.stop();
cout << "Base pool creation time: " << std::setprecision(10)
<< bench.getElapsedSec() << " seconds." << endl;
basepool.write_ascii("out.stl");
return EXIT_SUCCESS;
}
示例5: p
void BenchWidget::paintEvent(QPaintEvent *)
{
if (m_done)
return;
QPainter p(this);
m_benchmark->begin(&p, 100);
PaintingRectAdjuster adjuster;
adjuster.setNewBenchmark(m_benchmark);
adjuster.reset(rect());
for (int i = 0; i < 100; ++i)
m_benchmark->draw(&p, adjuster.newPaintingRect(), i);
m_benchmark->end(&p);
++m_iteration;
uint currentElapsed = timer.isNull() ? 0 : timer.elapsed();
timer.restart();
m_total += currentElapsed;
// warm up for at most 5 iterations or half a second
if (m_iteration >= 5 || m_total >= 500) {
iterationTimes << currentElapsed;
if (iterationTimes.size() >= 5) {
qreal mean = 0;
qreal stddev = 0;
uint min = INT_MAX;
for (int i = 0; i < iterationTimes.size(); ++i) {
mean += iterationTimes.at(i);
min = qMin(min, iterationTimes.at(i));
}
mean /= qreal(iterationTimes.size());
for (int i = 0; i < iterationTimes.size(); ++i) {
qreal delta = iterationTimes.at(i) - mean;
stddev += delta * delta;
}
stddev = qSqrt(stddev / iterationTimes.size());
stddev = 100 * stddev / mean;
// do 50 iterations, break earlier if we spend more than 5 seconds or have a low std deviation after 2 seconds
if (iterationTimes.size() >= 50 || m_total >= 5000 || (m_total >= 2000 && stddev < 4)) {
m_result = min;
m_done = true;
return;
}
}
}
}
示例6: main
int main(const int argc, const char *argv[]) {
using namespace Slic3r;
using std::cout; using std::endl;
if(argc < 2) {
cout << USAGE_STR << endl;
return EXIT_SUCCESS;
}
TriangleMesh model;
Benchmark bench;
model.ReadSTLFile(argv[1]);
model.align_to_origin();
ExPolygons ground_slice;
sla::Contour3D mesh;
// TriangleMesh basepool;
sla::base_plate(model, ground_slice, 0.1f);
if(ground_slice.empty()) return EXIT_FAILURE;
ExPolygon bottom_plate = ground_slice.front();
ExPolygon top_plate = bottom_plate;
sla::offset(top_plate, coord_t(3.0/SCALING_FACTOR));
sla::offset(bottom_plate, coord_t(1.0/SCALING_FACTOR));
bench.start();
Polygons top_plate_triangles, bottom_plate_triangles;
top_plate.triangulate_p2t(&top_plate_triangles);
bottom_plate.triangulate_p2t(&bottom_plate_triangles);
auto top_plate_mesh = sla::convert(top_plate_triangles, coord_t(3.0/SCALING_FACTOR), false);
auto bottom_plate_mesh = sla::convert(bottom_plate_triangles, 0, true);
mesh.merge(bottom_plate_mesh);
mesh.merge(top_plate_mesh);
sla::Contour3D w = sla::walls(bottom_plate.contour, top_plate.contour, 0, 3, 2.0, [](){});
mesh.merge(w);
// sla::create_base_pool(ground_slice, basepool);
bench.stop();
cout << "Base pool creation time: " << std::setprecision(10)
<< bench.getElapsedSec() << " seconds." << endl;
// basepool.write_ascii("out.stl");
std::fstream outstream("out.obj", std::fstream::out);
mesh.to_obj(outstream);
return EXIT_SUCCESS;
}
示例7: next
Benchmark* next() {
Benchmark* bench = nullptr;
// skips non matching benches
while ((bench = this->innerNext()) &&
(SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) ||
!bench->isSuitableFor(Benchmark::kGPU_Backend))) {
delete bench;
}
return bench;
}
示例8: perform_test_trivial
void perform_test_trivial() {
Benchmark s;
typedef ParserResultElement<Benchmark> Parser;
Parser p(s);
{
const std::string test = "bench123";
OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
if(s.name() != test)
OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
}
}
示例9: TEST_F
TEST_F(PerformanceTest, DISABLED_test_performance) {
DiskHammalFactory factory(GBYTES11FILE);
OutputWriter writer(GBYTESRESULT);
JobConfiguration configuration(1, 150 * 1024 * 1024, 10, 20);
JobClient client(configuration, factory, writer);
SimpleWordMapper mapper;
Benchmark benchmark;
benchmark.start();
client.run_job(mapper);
std::cout << "Elapsed time in second:" << benchmark.end() << std::endl;
}
示例10: read
double read(const char * filename, std::streampos size, int n_files, int blocksize)
{
if (debug) printf("\n%d files: ", n_files);
FILE * files[n_files];
// Open files, and set pos
for (int i = 0; i<n_files; ++i)
{
files[i] = fopen ( filename, "rb" );
long int pos = (size/n_files)*i;
fseek ( files[i], pos, SEEK_SET );
if (debug) printf("%lld, ", (unsigned long long) pos);
}
if (debug) printf("\n");
// Read size/n_files bytes from all files
Benchmark t; t.start();
uint32_t * buffer = (uint32_t *) malloc(blocksize);
// Every slice is 250' / number of files big
for (uint32_t i=0; i<(size/n_files); i+=blocksize)
{
// should be unrolled?
for (int j = 0; j<n_files; ++j)
{
// size_t res =
fread(buffer, 1, blocksize, files[j] );
/*
for (uint32_t z=0; z<blocksize/sizeof(int); ++z)
{
if (buffer[z] == 0)
printf("Read first byte\n");
if (buffer[z] == 249999999)
printf("Read last byte\n");
// fprintf(stderr, "Reading %d \n", buffer[z]);
}
//*/
}
}
t.stop();
// Close all files
free(buffer);
for (int i = 0; i<n_files; ++i)
fclose(files[i]);
return t.getSecs();
}
示例11: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Benchmark benchmark;
for (int i = 0; i < 5; ++i)
{
benchmark.test();
}
return a.exec();
}
示例12: main
int main(int argc, char** argv) {
ArgParser args(argc, argv);
if (!args.isSet("i")) usage(argv);
const std::string algo = args.get<std::string>("a", "pairwise"),
indexfn = args.get<std::string>("i"),
queryfn = args.get<std::string>("q", "queries.txt");
const uint32_t threshold = args.get<uint32_t>("t", 3);
Timer timer;
// load queries
std::vector<std::vector<uint32_t>> queries;
loadQueries(queries, queryfn);
std::cout << queries.size() << " queries loaded in " << timer.getAndReset() << "s" << std::endl;
// load index
Index* index = loadIndex(algo, indexfn);
if (index == nullptr) {
usage(argv);
}
std::cout << "Loaded index in " << timer.getAndReset() << "s" << std::endl;
// create benchmark object
Benchmark *benchmark = createBenchmark(algo, threshold);
benchmark->setIndex(index);
std::cout << "Querying index with " << queries.size() << " queries..." << std::endl;
timer.reset();
// Query!
for (const std::vector<uint32_t> &query : queries) {
benchmark->query(query);
}
double queryDuration = timer.get();
std::cout << "Queried index in " << queryDuration << "s" << std::endl;
std::cout << "RESULT"
<< " algo=" << algo
<< " index=" << indexfn
<< " queries=" << queryfn
<< " numQueries=" << queries.size()
<< " queryDuration=" << queryDuration
<< " msPerQuery=" << queryDuration * 1000 / queries.size()
// TODO max/min query time
<< std::endl;
}
示例13: close
void Benchmark::close(bool print)
{
if (current == NULL)
throw std::runtime_error("No active benchmark to close");
Benchmark * toClose = current;
#ifndef WIN32
toClose->closingTime = steady_clock::now();
#endif
current = toClose->father;
if (print)
toClose->print();
// Suppress Benchmark if the link is lost
if (current == NULL)
delete(toClose);
}
示例14: PRE1_level1_encrypt
BOOL
PRE1_level1_encrypt(CurveParams ¶ms, Big &plaintext, ProxyPK_PRE1 &publicKey, ProxyCiphertext_PRE1 &ciphertext)
{
#ifdef BENCHMARKING
gettimeofday(&gTstart, &gTz);
#endif
SAFESTATIC Big k;
SAFESTATIC ZZn2 temp, c1, c2;
SAFESTATIC ZZn2 zPlaintext;
// Select a random value k \in Z*q, and compute res1 = Zpub1^k
k = rand(params.q);
c1 = pow(publicKey.Zpub1, k);
// Compute res2 = plaintext * Z^k
temp = pow(params.Z, k);
//cout << "encrypt: params.Z = " << params.Z << endl;
//cout << "encrypt: temp = " << temp << endl;
zPlaintext.set(plaintext, 0);
//cout << "encrypt: plaintext = " << zPlaintext << endl;
c2 = zPlaintext * temp;
//cout << "encrypt: c1 = " << c1 << endl;
//cout << "encrypt: c2 = " << c2 << endl;
// Set the ciphertext data structure with (c1, c2)
ciphertext.set(CIPH_FIRST_LEVEL, c1, c2);
#ifdef BENCHMARKING
gettimeofday(&gTend, &gTz);
gBenchmark.CollectTiming(LEVELONEENCTIMING, CalculateUsecs(gTstart, gTend));
#endif
return true;
}
示例15: PRE1_level2_encrypt
BOOL PRE1_level2_encrypt(CurveParams ¶ms, Big &plaintext, ProxyPK_PRE1 &publicKey, ProxyCiphertext_PRE1 &ciphertext)
{
#ifdef BENCHMARKING
gettimeofday(&gTstart, &gTz);
#endif
SAFESTATIC Big k;
SAFESTATIC ECn c1;
SAFESTATIC ZZn2 temp, c2;
SAFESTATIC ZZn2 zPlaintext;
// Select a random value k \in Z*q and compute res1 = (k * P)
k = rand(params.q);
c1 = k * params.P;
// Compute res2 = plaintext * Zpub1^k
zPlaintext.set(plaintext, 0);
temp = pow(publicKey.Zpub1, k);
c2 = zPlaintext * temp;
// Set the ciphertext structure with (c1, c2)
ciphertext.set(CIPH_SECOND_LEVEL, c1, c2);
#ifdef BENCHMARKING
gettimeofday(&gTend, &gTz);
gBenchmark.CollectTiming(LEVELTWOENCTIMING, CalculateUsecs(gTstart, gTend));
#endif
return true;
}