MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / BM_CommandLine

Function BM_CommandLine

src/benchmark/Performance.cpp:833–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

831}
832
833static void BM_CommandLine(benchmark::State& state, const BenchmarkConfig& config,
834 int iteration) {
835 const std::string input_path =
836 GetTemporaryFileRegistry().Create("benchmark-cli-input", ".txt");
837 const std::string output_path =
838 GetTemporaryFileRegistry().Create("benchmark-cli-output", ".txt");
839 const std::string measured_path =
840 GetTemporaryFileRegistry().Create("benchmark-cli-measured", ".json");
841
842 std::ostringstream os;
843 for (int i = 0; i < iteration; i++) {
844 os << "Open Chinese Convert 開放中文轉換" << i << std::endl;
845 }
846 const std::string text = os.str();
847 {
848 std::ofstream stream(input_path.c_str(), std::ios::binary);
849 stream << text;
850 }
851
852 MeasuredResult measured;
853 size_t total_input_bytes = 0;
854 double total_load_ms = 0.0;
855 double total_convert_ms = 0.0;
856 double total_write_ms = 0.0;
857 double total_total_ms = 0.0;
858 for (auto _ : state) {
859 RunCommandLineConversion(config, input_path, output_path, measured_path);
860 measured = ParseMeasuredResult(measured_path);
861 total_input_bytes += measured.inputBytes == 0 ? text.size() : measured.inputBytes;
862 total_load_ms += measured.loadMs;
863 total_convert_ms += measured.convertMs;
864 total_write_ms += measured.writeMs;
865 total_total_ms += measured.totalMs;
866 }
867 SetCommandLineCounters(state, total_input_bytes, total_load_ms,
868 total_convert_ms, total_write_ms, total_total_ms);
869}
870
871bool RegisterBenchmarks() {
872 const std::vector<BenchmarkConfig> initialization_configs =

Callers 1

RegisterBenchmarksFunction · 0.85

Calls 6

RunCommandLineConversionFunction · 0.85
ParseMeasuredResultFunction · 0.85
SetCommandLineCountersFunction · 0.85
CreateMethod · 0.45
strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected