2019-02-24 00:28:20 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cctype>
|
2018-12-31 10:00:19 +08:00
|
|
|
#ifndef _MSC_VER
|
2019-02-24 00:28:20 +08:00
|
|
|
#include <dirent.h>
|
2018-12-31 10:00:19 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2019-02-24 00:28:20 +08:00
|
|
|
#include <cinttypes>
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2018-11-30 22:37:57 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
2018-08-21 05:27:25 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <cstring>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
2018-03-23 12:05:32 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-11-30 22:37:57 +08:00
|
|
|
|
|
|
|
#include "linux-perf-events.h"
|
2018-12-19 11:18:23 +08:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <libgen.h>
|
|
|
|
#endif
|
2018-05-31 10:46:28 +08:00
|
|
|
//#define DEBUG
|
2018-11-30 22:37:57 +08:00
|
|
|
#include "simdjson/common_defs.h"
|
2019-07-31 05:18:10 +08:00
|
|
|
#include "simdjson/isadetection.h"
|
2018-11-30 22:37:57 +08:00
|
|
|
#include "simdjson/jsonioutil.h"
|
2018-12-19 11:48:24 +08:00
|
|
|
#include "simdjson/jsonparser.h"
|
2018-11-30 22:37:57 +08:00
|
|
|
#include "simdjson/parsedjson.h"
|
|
|
|
#include "simdjson/stage1_find_marks.h"
|
2019-01-01 06:13:32 +08:00
|
|
|
#include "simdjson/stage2_build_tape.h"
|
2019-07-29 10:46:33 +08:00
|
|
|
namespace simdjson {
|
2019-07-31 05:18:10 +08:00
|
|
|
Architecture _find_best_supported_implementation() {
|
|
|
|
constexpr uint32_t haswell_flags =
|
|
|
|
instruction_set::AVX2 | instruction_set::PCLMULQDQ |
|
|
|
|
instruction_set::BMI1 | instruction_set::BMI2;
|
|
|
|
constexpr uint32_t westmere_flags =
|
|
|
|
instruction_set::SSE42 | instruction_set::PCLMULQDQ;
|
2019-07-29 10:46:33 +08:00
|
|
|
uint32_t supports = detect_supported_architectures();
|
|
|
|
// Order from best to worst (within architecture)
|
|
|
|
if ((haswell_flags & supports) == haswell_flags) {
|
2019-07-31 05:18:10 +08:00
|
|
|
return Architecture::HASWELL;
|
2019-07-29 10:46:33 +08:00
|
|
|
}
|
|
|
|
if ((westmere_flags & supports) == westmere_flags) {
|
2019-07-31 05:18:10 +08:00
|
|
|
return Architecture::WESTMERE;
|
2019-07-29 10:46:33 +08:00
|
|
|
}
|
2019-07-31 05:18:10 +08:00
|
|
|
if (instruction_set::NEON)
|
|
|
|
return Architecture::ARM64;
|
2019-07-29 10:46:33 +08:00
|
|
|
|
2019-07-31 05:18:10 +08:00
|
|
|
return Architecture::NONE;
|
2019-07-29 10:46:33 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 05:18:10 +08:00
|
|
|
using unified_functype = int(const uint8_t *buf, size_t len, ParsedJson &pj);
|
|
|
|
using stage1_functype = int(const uint8_t *buf, size_t len, ParsedJson &pj);
|
2019-07-29 10:46:33 +08:00
|
|
|
|
|
|
|
extern unified_functype *unified_ptr;
|
|
|
|
|
|
|
|
extern stage1_functype *stage1_ptr;
|
|
|
|
|
|
|
|
int unified_machine_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj) {
|
2019-07-31 05:18:10 +08:00
|
|
|
Architecture best_implementation = _find_best_supported_implementation();
|
2019-07-29 10:46:33 +08:00
|
|
|
// Selecting the best implementation
|
|
|
|
switch (best_implementation) {
|
|
|
|
#ifdef IS_X86_64
|
2019-07-31 05:18:10 +08:00
|
|
|
case Architecture::HASWELL:
|
|
|
|
unified_ptr = &unified_machine<Architecture::HASWELL>;
|
2019-07-29 10:46:33 +08:00
|
|
|
break;
|
2019-07-31 05:18:10 +08:00
|
|
|
case Architecture::WESTMERE:
|
|
|
|
unified_ptr = &unified_machine<Architecture::WESTMERE>;
|
2019-07-29 10:46:33 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef IS_ARM64
|
2019-07-31 05:18:10 +08:00
|
|
|
case Architecture::ARM64:
|
|
|
|
unified_ptr = &unified_machine<Architecture::ARM64>;
|
2019-07-29 10:46:33 +08:00
|
|
|
break;
|
|
|
|
#endif
|
2019-07-31 05:18:10 +08:00
|
|
|
default:
|
2019-07-29 10:46:33 +08:00
|
|
|
std::cerr << "The processor is not supported by simdjson." << std::endl;
|
|
|
|
return simdjson::UNEXPECTED_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return unified_ptr(buf, len, pj);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Responsible to select the best json_parse implementation
|
2019-07-31 05:18:10 +08:00
|
|
|
int find_structural_bits_dispatch(const uint8_t *buf, size_t len,
|
|
|
|
ParsedJson &pj) {
|
|
|
|
Architecture best_implementation = _find_best_supported_implementation();
|
2019-07-29 10:46:33 +08:00
|
|
|
// Selecting the best implementation
|
|
|
|
switch (best_implementation) {
|
|
|
|
#ifdef IS_X86_64
|
2019-07-31 05:18:10 +08:00
|
|
|
case Architecture::HASWELL:
|
|
|
|
stage1_ptr = &find_structural_bits<Architecture::HASWELL>;
|
2019-07-29 10:46:33 +08:00
|
|
|
break;
|
2019-07-31 05:18:10 +08:00
|
|
|
case Architecture::WESTMERE:
|
|
|
|
stage1_ptr = &find_structural_bits<Architecture::WESTMERE>;
|
2019-07-29 10:46:33 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef IS_ARM64
|
2019-07-31 05:18:10 +08:00
|
|
|
case Architecture::ARM64:
|
|
|
|
stage1_ptr = &find_structural_bits<Architecture::ARM64>;
|
2019-07-29 10:46:33 +08:00
|
|
|
break;
|
|
|
|
#endif
|
2019-07-31 05:18:10 +08:00
|
|
|
default:
|
2019-07-29 10:46:33 +08:00
|
|
|
std::cerr << "The processor is not supported by simdjson." << std::endl;
|
|
|
|
return simdjson::UNEXPECTED_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stage1_ptr(buf, len, pj);
|
|
|
|
}
|
|
|
|
|
|
|
|
stage1_functype *stage1_ptr = &find_structural_bits_dispatch;
|
|
|
|
unified_functype *unified_ptr = &unified_machine_dispatch;
|
2019-07-31 05:18:10 +08:00
|
|
|
} // namespace simdjson
|
2018-03-23 12:05:32 +08:00
|
|
|
|
2018-08-21 05:27:25 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2018-11-10 10:31:14 +08:00
|
|
|
bool verbose = false;
|
2018-11-24 11:20:57 +08:00
|
|
|
bool dump = false;
|
2019-07-31 05:18:10 +08:00
|
|
|
bool json_output = false;
|
|
|
|
bool force_one_iteration = false;
|
|
|
|
bool just_data = false;
|
2018-12-31 10:00:19 +08:00
|
|
|
#ifndef _MSC_VER
|
2018-11-10 10:31:14 +08:00
|
|
|
int c;
|
|
|
|
|
2019-02-24 00:28:20 +08:00
|
|
|
while ((c = getopt(argc, argv, "1vdt")) != -1) {
|
2018-12-19 11:48:24 +08:00
|
|
|
switch (c) {
|
|
|
|
case 't':
|
2019-07-31 05:18:10 +08:00
|
|
|
just_data = true;
|
2018-12-19 11:48:24 +08:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = true;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
dump = true;
|
|
|
|
break;
|
|
|
|
case 'j':
|
2019-07-31 05:18:10 +08:00
|
|
|
json_output = true;
|
2018-12-19 11:48:24 +08:00
|
|
|
break;
|
|
|
|
case '1':
|
2019-07-31 05:18:10 +08:00
|
|
|
force_one_iteration = true;
|
2018-12-19 11:48:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2019-07-31 05:18:10 +08:00
|
|
|
}
|
2018-12-31 10:00:19 +08:00
|
|
|
#else
|
|
|
|
int optind = 1;
|
|
|
|
#endif
|
2018-11-10 10:31:14 +08:00
|
|
|
if (optind >= argc) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cerr << "Usage: " << argv[0] << " <jsonfile>" << std::endl;
|
2018-08-21 05:27:25 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2018-12-19 11:48:24 +08:00
|
|
|
const char *filename = argv[optind];
|
|
|
|
if (optind + 1 < argc) {
|
2019-07-31 05:18:10 +08:00
|
|
|
std::cerr << "warning: ignoring everything after " << argv[optind + 1]
|
|
|
|
<< std::endl;
|
2018-08-21 05:27:25 +08:00
|
|
|
}
|
2019-02-24 00:28:20 +08:00
|
|
|
if (verbose) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cout << "[verbose] loading " << filename << std::endl;
|
|
|
|
}
|
2019-07-03 03:21:00 +08:00
|
|
|
simdjson::padded_string p;
|
2018-11-28 03:37:59 +08:00
|
|
|
try {
|
2019-07-03 03:21:00 +08:00
|
|
|
simdjson::get_corpus(filename).swap(p);
|
2018-12-19 11:48:24 +08:00
|
|
|
} catch (const std::exception &e) { // caught by reference to base
|
2018-11-28 03:37:59 +08:00
|
|
|
std::cout << "Could not load the file " << filename << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2019-02-24 00:28:20 +08:00
|
|
|
if (verbose) {
|
2019-07-31 05:18:10 +08:00
|
|
|
std::cout << "[verbose] loaded " << filename << " (" << p.size()
|
|
|
|
<< " bytes)" << std::endl;
|
|
|
|
}
|
2018-07-14 10:22:30 +08:00
|
|
|
#if defined(DEBUG)
|
2018-12-28 09:09:25 +08:00
|
|
|
const uint32_t iterations = 1;
|
2018-03-23 12:05:32 +08:00
|
|
|
#else
|
2018-12-28 09:09:25 +08:00
|
|
|
const uint32_t iterations =
|
2019-07-31 05:18:10 +08:00
|
|
|
force_one_iteration ? 1 : (p.size() < 1 * 1000 * 1000 ? 1000 : 10);
|
2018-03-23 12:05:32 +08:00
|
|
|
#endif
|
2019-05-10 05:59:51 +08:00
|
|
|
std::vector<double> res;
|
2018-08-21 05:27:25 +08:00
|
|
|
res.resize(iterations);
|
2019-07-31 05:18:10 +08:00
|
|
|
if (!just_data)
|
|
|
|
printf("number of iterations %u \n", iterations);
|
2018-05-07 19:33:23 +08:00
|
|
|
#if !defined(__linux__)
|
|
|
|
#define SQUASH_COUNTERS
|
2019-07-31 05:18:10 +08:00
|
|
|
if (just_data) {
|
|
|
|
printf("just_data (-t) flag only works under linux.\n");
|
2018-12-19 11:18:23 +08:00
|
|
|
}
|
2018-05-07 19:33:23 +08:00
|
|
|
#endif
|
2019-07-31 05:18:10 +08:00
|
|
|
{ // practice run
|
2019-07-29 10:46:33 +08:00
|
|
|
simdjson::ParsedJson pj;
|
2019-07-31 05:18:10 +08:00
|
|
|
bool allocok = pj.allocate_capacity(p.size());
|
|
|
|
if (allocok) {
|
|
|
|
simdjson::stage1_ptr((const uint8_t *)p.data(), p.size(), pj);
|
|
|
|
simdjson::unified_ptr(
|
|
|
|
(const uint8_t
|
|
|
|
*)(const uint8_t
|
|
|
|
*)(const uint8_t
|
|
|
|
*)(const uint8_t
|
|
|
|
*)(const uint8_t
|
|
|
|
*)(const uint8_t
|
|
|
|
*)(const uint8_t
|
|
|
|
*)(const uint8_t *)
|
|
|
|
p.data(),
|
|
|
|
p.size(), pj);
|
2019-07-29 10:46:33 +08:00
|
|
|
}
|
|
|
|
}
|
2018-05-07 19:33:23 +08:00
|
|
|
#ifndef SQUASH_COUNTERS
|
2019-05-10 05:59:51 +08:00
|
|
|
std::vector<int> evts;
|
2018-08-21 05:27:25 +08:00
|
|
|
evts.push_back(PERF_COUNT_HW_CPU_CYCLES);
|
|
|
|
evts.push_back(PERF_COUNT_HW_INSTRUCTIONS);
|
2018-10-04 21:47:34 +08:00
|
|
|
evts.push_back(PERF_COUNT_HW_BRANCH_MISSES);
|
2018-11-28 23:53:57 +08:00
|
|
|
evts.push_back(PERF_COUNT_HW_CACHE_REFERENCES);
|
|
|
|
evts.push_back(PERF_COUNT_HW_CACHE_MISSES);
|
2018-08-21 05:27:25 +08:00
|
|
|
LinuxEvents<PERF_TYPE_HARDWARE> unified(evts);
|
2019-05-10 05:59:51 +08:00
|
|
|
std::vector<unsigned long long> results;
|
2018-08-21 05:27:25 +08:00
|
|
|
results.resize(evts.size());
|
2019-01-01 06:39:06 +08:00
|
|
|
unsigned long cy0 = 0, cy1 = 0, cy2 = 0;
|
|
|
|
unsigned long cl0 = 0, cl1 = 0, cl2 = 0;
|
|
|
|
unsigned long mis0 = 0, mis1 = 0, mis2 = 0;
|
|
|
|
unsigned long cref0 = 0, cref1 = 0, cref2 = 0;
|
|
|
|
unsigned long cmis0 = 0, cmis1 = 0, cmis2 = 0;
|
2018-04-26 09:36:07 +08:00
|
|
|
#endif
|
2018-08-21 05:27:25 +08:00
|
|
|
bool isok = true;
|
2019-06-03 22:59:07 +08:00
|
|
|
#ifndef SQUASH_COUNTERS
|
2018-12-28 09:09:25 +08:00
|
|
|
for (uint32_t i = 0; i < iterations; i++) {
|
2019-02-24 00:28:20 +08:00
|
|
|
if (verbose) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cout << "[verbose] iteration # " << i << std::endl;
|
|
|
|
}
|
2018-12-07 11:34:18 +08:00
|
|
|
unified.start();
|
2019-07-03 03:21:00 +08:00
|
|
|
simdjson::ParsedJson pj;
|
2019-07-31 05:18:10 +08:00
|
|
|
bool allocok = pj.allocate_capacity(p.size());
|
2018-12-19 11:48:24 +08:00
|
|
|
if (!allocok) {
|
2018-12-07 11:34:18 +08:00
|
|
|
std::cerr << "failed to allocate memory" << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
unified.end(results);
|
|
|
|
cy0 += results[0];
|
|
|
|
cl0 += results[1];
|
|
|
|
mis0 += results[2];
|
|
|
|
cref0 += results[3];
|
|
|
|
cmis0 += results[4];
|
2019-02-24 00:28:20 +08:00
|
|
|
if (verbose) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cout << "[verbose] allocated memory for parsed JSON " << std::endl;
|
2019-06-03 22:59:07 +08:00
|
|
|
}
|
2018-08-21 05:27:25 +08:00
|
|
|
unified.start();
|
2019-07-31 05:18:10 +08:00
|
|
|
isok = (simdjson::stage1_ptr((const uint8_t *)p.data(), p.size(), pj) ==
|
|
|
|
simdjson::SUCCESS);
|
2018-08-21 05:27:25 +08:00
|
|
|
unified.end(results);
|
|
|
|
cy1 += results[0];
|
|
|
|
cl1 += results[1];
|
2018-10-04 21:47:34 +08:00
|
|
|
mis1 += results[2];
|
2018-11-28 23:53:57 +08:00
|
|
|
cref1 += results[3];
|
|
|
|
cmis1 += results[4];
|
2018-09-24 08:42:30 +08:00
|
|
|
if (!isok) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cout << "Failed during stage 1" << std::endl;
|
2018-08-21 05:27:25 +08:00
|
|
|
break;
|
2018-09-24 08:42:30 +08:00
|
|
|
}
|
2018-08-21 05:27:25 +08:00
|
|
|
unified.start();
|
2019-07-31 05:18:10 +08:00
|
|
|
isok = isok &&
|
|
|
|
(simdjson::SUCCESS ==
|
|
|
|
simdjson::unified_ptr((const uint8_t *)p.data(), p.size(), pj));
|
2018-09-24 08:42:30 +08:00
|
|
|
unified.end(results);
|
2019-01-01 06:39:06 +08:00
|
|
|
cy2 += results[0];
|
|
|
|
cl2 += results[1];
|
|
|
|
mis2 += results[2];
|
|
|
|
cref2 += results[3];
|
|
|
|
cmis2 += results[4];
|
2018-09-24 08:42:30 +08:00
|
|
|
if (!isok) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cout << "Failed during stage 2" << std::endl;
|
2018-08-21 05:27:25 +08:00
|
|
|
break;
|
2018-09-24 08:42:30 +08:00
|
|
|
}
|
2019-06-03 22:59:07 +08:00
|
|
|
}
|
2018-09-24 08:42:30 +08:00
|
|
|
#endif
|
2019-06-03 22:59:07 +08:00
|
|
|
// we do it again, this time just measuring the elapsed time
|
|
|
|
for (uint32_t i = 0; i < iterations; i++) {
|
|
|
|
if (verbose) {
|
|
|
|
std::cout << "[verbose] iteration # " << i << std::endl;
|
|
|
|
}
|
2019-07-03 03:21:00 +08:00
|
|
|
simdjson::ParsedJson pj;
|
2019-07-31 05:18:10 +08:00
|
|
|
bool allocok = pj.allocate_capacity(p.size());
|
2019-06-03 22:59:07 +08:00
|
|
|
if (!allocok) {
|
|
|
|
std::cerr << "failed to allocate memory" << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
if (verbose) {
|
|
|
|
std::cout << "[verbose] allocated memory for parsed JSON " << std::endl;
|
|
|
|
}
|
2018-09-24 08:42:30 +08:00
|
|
|
|
2019-06-03 22:59:07 +08:00
|
|
|
auto start = std::chrono::steady_clock::now();
|
2019-07-31 05:18:10 +08:00
|
|
|
isok = (simdjson::stage1_ptr((const uint8_t *)p.data(), p.size(), pj) ==
|
|
|
|
simdjson::SUCCESS);
|
|
|
|
isok = isok &&
|
|
|
|
(simdjson::SUCCESS ==
|
|
|
|
simdjson::unified_ptr((const uint8_t *)p.data(), p.size(), pj));
|
2018-08-21 05:27:25 +08:00
|
|
|
auto end = std::chrono::steady_clock::now();
|
|
|
|
std::chrono::duration<double> secs = end - start;
|
|
|
|
res[i] = secs.count();
|
2019-07-31 05:18:10 +08:00
|
|
|
if (!isok) {
|
|
|
|
std::cerr << pj.get_error_message() << std::endl;
|
2019-06-03 22:59:07 +08:00
|
|
|
std::cerr << "Could not parse. " << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2019-07-31 05:18:10 +08:00
|
|
|
}
|
|
|
|
simdjson::ParsedJson pj =
|
|
|
|
build_parsed_json(p); // do the parsing again to get the stats
|
|
|
|
if (!pj.is_valid()) {
|
|
|
|
std::cerr << pj.get_error_message() << std::endl;
|
2018-12-11 03:25:49 +08:00
|
|
|
std::cerr << "Could not parse. " << std::endl;
|
2018-12-07 11:34:18 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2019-06-04 01:24:54 +08:00
|
|
|
double min_result = *min_element(res.begin(), res.end());
|
2019-06-04 01:45:34 +08:00
|
|
|
double speedinGBs = (p.size()) / (min_result * 1000000000.0);
|
2018-05-07 19:33:23 +08:00
|
|
|
#ifndef SQUASH_COUNTERS
|
2019-01-01 06:39:06 +08:00
|
|
|
unsigned long total = cy0 + cy1 + cy2;
|
2019-07-31 05:18:10 +08:00
|
|
|
if (just_data) {
|
2018-12-19 11:48:24 +08:00
|
|
|
float cpb0 = (double)cy0 / (iterations * p.size());
|
|
|
|
float cpb1 = (double)cy1 / (iterations * p.size());
|
|
|
|
float cpb2 = (double)cy2 / (iterations * p.size());
|
2018-12-19 11:18:23 +08:00
|
|
|
float cpbtotal = (double)total / (iterations * p.size());
|
2018-12-19 11:48:24 +08:00
|
|
|
char *newfile = (char *)malloc(strlen(filename) + 1);
|
2019-04-25 05:31:47 +08:00
|
|
|
if (newfile == NULL) {
|
2018-12-19 11:48:24 +08:00
|
|
|
return EXIT_FAILURE;
|
2019-04-25 05:31:47 +08:00
|
|
|
}
|
2018-12-19 11:48:24 +08:00
|
|
|
::strcpy(newfile, filename);
|
|
|
|
char *snewfile = ::basename(newfile);
|
|
|
|
size_t nl = strlen(snewfile);
|
|
|
|
for (size_t j = nl - 1; j > 0; j--) {
|
|
|
|
if (snewfile[j] == '.') {
|
|
|
|
snewfile[j] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-07-31 05:18:10 +08:00
|
|
|
printf("\"%s\"\t%f\t%f\t%f\t%f\t%f\n", snewfile, cpb0, cpb1, cpb2, cpbtotal,
|
|
|
|
speedinGBs);
|
2018-12-19 11:48:24 +08:00
|
|
|
free(newfile);
|
2018-12-19 11:18:23 +08:00
|
|
|
} else {
|
2018-12-19 11:48:24 +08:00
|
|
|
printf("number of bytes %ld number of structural chars %u ratio %.3f\n",
|
|
|
|
p.size(), pj.n_structural_indexes,
|
|
|
|
(double)pj.n_structural_indexes / p.size());
|
|
|
|
printf("mem alloc instructions: %10lu cycles: %10lu (%.2f %%) ins/cycles: "
|
|
|
|
"%.2f mis. branches: %10lu (cycles/mis.branch %.2f) cache accesses: "
|
|
|
|
"%10lu (failure %10lu)\n",
|
|
|
|
cl0 / iterations, cy0 / iterations, 100. * cy0 / total,
|
|
|
|
(double)cl0 / cy0, mis0 / iterations, (double)cy0 / mis0,
|
|
|
|
cref1 / iterations, cmis0 / iterations);
|
|
|
|
printf(" mem alloc runs at %.2f cycles per input byte.\n",
|
|
|
|
(double)cy0 / (iterations * p.size()));
|
|
|
|
printf("stage 1 instructions: %10lu cycles: %10lu (%.2f %%) ins/cycles: "
|
|
|
|
"%.2f mis. branches: %10lu (cycles/mis.branch %.2f) cache accesses: "
|
|
|
|
"%10lu (failure %10lu)\n",
|
|
|
|
cl1 / iterations, cy1 / iterations, 100. * cy1 / total,
|
|
|
|
(double)cl1 / cy1, mis1 / iterations, (double)cy1 / mis1,
|
|
|
|
cref1 / iterations, cmis1 / iterations);
|
|
|
|
printf(" stage 1 runs at %.2f cycles per input byte.\n",
|
|
|
|
(double)cy1 / (iterations * p.size()));
|
2018-08-21 05:27:25 +08:00
|
|
|
|
2018-12-19 11:48:24 +08:00
|
|
|
printf("stage 2 instructions: %10lu cycles: %10lu (%.2f %%) ins/cycles: "
|
|
|
|
"%.2f mis. branches: %10lu (cycles/mis.branch %.2f) cache "
|
|
|
|
"accesses: %10lu (failure %10lu)\n",
|
2019-01-01 06:39:06 +08:00
|
|
|
cl2 / iterations, cy2 / iterations, 100. * cy2 / total,
|
|
|
|
(double)cl2 / cy2, mis2 / iterations, (double)cy2 / mis2,
|
|
|
|
cref2 / iterations, cmis2 / iterations);
|
2019-01-01 06:13:32 +08:00
|
|
|
printf(" stage 2 runs at %.2f cycles per input byte and ",
|
2019-01-01 06:39:06 +08:00
|
|
|
(double)cy2 / (iterations * p.size()));
|
2018-12-19 11:48:24 +08:00
|
|
|
printf("%.2f cycles per structural character.\n",
|
2019-01-01 06:39:06 +08:00
|
|
|
(double)cy2 / (iterations * pj.n_structural_indexes));
|
2018-08-21 05:27:25 +08:00
|
|
|
|
2018-12-19 11:48:24 +08:00
|
|
|
printf(" all stages: %.2f cycles per input byte.\n",
|
|
|
|
(double)total / (iterations * p.size()));
|
2019-07-31 05:18:10 +08:00
|
|
|
printf("Estimated average frequency: %.3f GHz.\n",
|
|
|
|
(double)total / (iterations * min_result * 1000000000.0));
|
2018-12-19 11:18:23 +08:00
|
|
|
}
|
2018-04-26 09:36:07 +08:00
|
|
|
#endif
|
2019-07-31 05:18:10 +08:00
|
|
|
if (!just_data) {
|
2019-05-10 05:59:51 +08:00
|
|
|
std::cout << "Min: " << min_result << " bytes read: " << p.size()
|
2019-07-31 05:18:10 +08:00
|
|
|
<< " Gigabytes/second: " << speedinGBs << std::endl;
|
2019-06-04 01:45:34 +08:00
|
|
|
}
|
2019-07-31 05:18:10 +08:00
|
|
|
if (json_output) {
|
|
|
|
isok = isok && pj.print_json(std::cout);
|
2018-12-07 06:40:32 +08:00
|
|
|
}
|
2018-12-19 11:48:24 +08:00
|
|
|
if (dump) {
|
2018-12-11 04:16:31 +08:00
|
|
|
isok = isok && pj.dump_raw_tape(std::cout);
|
2018-12-07 06:40:32 +08:00
|
|
|
}
|
2018-08-21 05:27:25 +08:00
|
|
|
if (!isok) {
|
2018-12-31 10:00:19 +08:00
|
|
|
fprintf(stderr, " Parsing failed. \n ");
|
2018-08-21 05:27:25 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
2018-03-23 12:05:32 +08:00
|
|
|
}
|