Skip to content

Commit 317a4c5

Browse files
committed
- Updated to version 1.6.3
- e_subst has been rewritten and no longer requires specifying the format string twice. - Added the e_int method for formatting integers. - Bug fixes and code optimizations. - Benchmarks and tests added. - Updated documentation and benchmark results. - Обновлена версия на 1.6.3 - e_subst переделан и теперь не требует указывать форматную строку дважды. - Добавлен метод e_int для форматирования целых чисел. - Исправлены ошибки, оптимизирован код. - Добавлены бенчмарки и тесты. - Обновлена документация и результаты бенчмарков.
1 parent 15c78e6 commit 317a4c5

22 files changed

Lines changed: 5794 additions & 5067 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include(FetchContent)
55

66
project(
77
simstr
8-
VERSION 1.6.2
8+
VERSION 1.6.3
99
DESCRIPTION "Yet another modern C++ string library"
1010
HOMEPAGE_URL "https://github.com/orefkov/simstr"
1111
LANGUAGES CXX

bench/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ cmake_minimum_required (VERSION 3.15)
66
add_executable(benchStr bench_str.cpp bench.h)
77
target_link_libraries(benchStr simstr::simstr benchmark::benchmark)
88
target_compile_features(benchStr PUBLIC cxx_std_23)
9+
target_compile_definitions(benchStr PRIVATE SIMSTR_VERSION="${PROJECT_VERSION}")
910

1011
add_executable(process_result process_result.cpp)
1112
target_link_libraries(process_result simstr_simstr)
12-
1313
if (EMSCRIPTEN)
1414
#target_link_options(benchStr PRIVATE -sSTACK_SIZE=1048576 -sINITIAL_MEMORY=128MB -sALLOW_MEMORY_GROWTH=0)
1515
set_target_properties (benchStr PROPERTIES SUFFIX .html)

bench/bench_str.cpp

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void ConcatSimToSimHexS(benchmark::State& state) {
155155
for (auto _: state) {
156156
for (unsigned i = 1; i <= 100'000; i *= 10) {
157157
benchmark::DoNotOptimize(s1);
158-
stringa str = e_subst(S_FRM("{}{} end"), s1, e_hex<HexFlags::Short>(i));
158+
stringa str = e_subst("{}{} end", s1, e_hex<HexFlags::Short>(i));
159159
benchmark::DoNotOptimize(str);
160160
}
161161
}
@@ -176,13 +176,58 @@ void ConcatSimToSimHexVS(benchmark::State& state) {
176176
BENCHMARK(__)->Name("----- Concatenate string + Hex Number + \"Literal\" ---------")->Repetitions(1);
177177
BENCHMARK(ConcatStdToFmtHex) ->Name("Concat std::string and format hex number and literal to std::string");
178178
BENCHMARK(ConcatAllFmtToHex) ->Name("std::format std::string and hex number by literal to std::string");
179-
BENCHMARK(ConcatStdToCharsHex) ->Name("Concat std::string and std::tochars and string to std::string");
179+
BENCHMARK(ConcatStdToCharsHex) ->Name("Concat std::string and std::to_chars and string to std::string");
180180
BENCHMARK(ConcatSimToStdHex) ->Name("Concat std::string and hex number and literal by StrExpr to std::string");
181181
BENCHMARK(ConcatSimToSimHex) ->Name("Concat stringa and hex number and literal by StrExpr to simstr::stringa");
182182
BENCHMARK(ConcatSimToSimHexC) ->Name("Concat stringa and hex number and literal by e_concat to simstr::stringa");
183183
BENCHMARK(ConcatSimToSimHexS) ->Name("Subst stringa and hex number by e_subst literal to simstr::stringa");
184184
BENCHMARK(ConcatSimToSimHexVS) ->Name("Subst stringa and hex number by e_vsubst stra to simstr::stringa");
185185

186+
void SubstSimToSimBin(benchmark::State& state) {
187+
static bool first = true;
188+
for (auto _: state) {
189+
for (unsigned i = 1; i <= 100'000; i *= 10) {
190+
stringa str = e_subst("art {} end", e_int<8, f::w<10> | f::p | f::z>(i));
191+
benchmark::DoNotOptimize(str);
192+
}
193+
}
194+
}
195+
196+
void FormatStdToStdBin(benchmark::State& state) {
197+
for (auto _: state) {
198+
for (unsigned i = 1; i <= 100'000; i *= 10) {
199+
std::string str = std::format("art {:#010o} end", i);
200+
benchmark::DoNotOptimize(str);
201+
}
202+
}
203+
}
204+
205+
void VSubstSimToSimBin(benchmark::State& state) {
206+
ssa pattern = "art {} end";
207+
for (auto _: state) {
208+
for (unsigned i = 1; i <= 100'000; i *= 10) {
209+
stringa str = e_vsubst(pattern, e_int<8, f::w<10> | f::p | f::z>(i));
210+
benchmark::DoNotOptimize(str);
211+
}
212+
}
213+
}
214+
215+
void VFormatStdToStdBin(benchmark::State& state) {
216+
std::string_view pattern = "art {:#010o} end";
217+
static bool first = true;
218+
for (auto _: state) {
219+
for (unsigned i = 1; i <= 100'000; i *= 10) {
220+
std::string str = std::vformat(pattern, std::make_format_args(i));
221+
benchmark::DoNotOptimize(str);
222+
}
223+
}
224+
}
225+
BENCHMARK(__)->Name("----- format/vformat and subst/vsubst octal number ---------")->Repetitions(1);
226+
BENCHMARK(SubstSimToSimBin) ->Name("e_subst(\"art {} end\", e_int<8, f::w<10> | f::p | f::z>(i))");
227+
BENCHMARK(FormatStdToStdBin) ->Name("std::format(\"art {:#010o} end\", i)");
228+
BENCHMARK(VSubstSimToSimBin) ->Name("e_vsubst(pattern, e_int<8, f::w<10> | f::p | f::z>(i))");
229+
BENCHMARK(VFormatStdToStdBin) ->Name("std::vformat(pattern, std::make_format_args(i))");
230+
186231
void ConcatStdToStdS(benchmark::State& state) {
187232
std::string s1 = "start ";
188233
for (auto _: state) {
@@ -2343,7 +2388,10 @@ BENCHMARK(BuildFuncNameSimStr) ->Name("Build func full name stringa;");
23432388
BENCHMARK(BuildFuncNameSimStr1) ->Name("Build func full name stringa 1;");
23442389

23452390
int main(int argc, char** argv) {
2346-
char arg1[] = "--benchmark_repetitions=10", arg2[] = "--benchmark_report_aggregates_only=true";
2391+
std::cout << "Benchmarks of simstr, version " SIMSTR_VERSION << "\n"
2392+
<< "Sources: https://github.com/orefkov/simstr\n"
2393+
<< "Results: https://orefkov.github.io/simstr/results.html\n" << std::endl;
2394+
char arg1[] = "--benchmark_repetitions=4", arg2[] = "--benchmark_report_aggregates_only=true";
23472395
char* my_params[] = {argv[0], arg1, arg2};
23482396
if (argc < 2) {
23492397
argc = 3;

bench/header.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
}
266266
});
267267
</script>
268-
</head><body><div class="header"><h2>SimStr benchmarks results</h2>
268+
</head><body><div class="header"><h2>simstr benchmarks results</h2>
269+
<div style="font-size:16pt;margin:20px;text-align:center"><a href="https://github.com/orefkov/simstr">simstr</a> is a powerful and convenient library for productive work with strings in C++.</div>
269270
<span>All times in ns.</span>
270271
<span><a href="https://github.com/orefkov/simstr/blob/main/bench/bench_str.cpp">Source for benchmarks</a></span>

bench/process_result.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void write_platforms_cpu(out_t& out, const results_vector& results) {
117117
size_t rp = r.cpu_info_.find('(') + 1, lp = r.cpu_info_.find(')', rp);
118118
ssa shortCpuInfo = r.cpu_info_.from_to(rp, lp);
119119
ssa cpuInfo = r.cpu_info_(lp + 2);
120-
out.append_formatted(R"--(
120+
out += e_subst(R"--(
121121
<li><span class="platform">{}</span><span class="tooltip">{}<span class="tooltiptext">{}</span></span>&nbsp;Include in charts: <input type="checkbox" id="pl{}" checked onchange="buildCharts()"/></li>)--",
122122
r.platform_, shortCpuInfo, cpuInfo, counter++);
123123
script += "'" + e_repl(r.platform_.to_str(), "'", "\\'") + "'" + e_choice(&r == &results.back(), "]", ",");

0 commit comments

Comments
 (0)