Skip to content

Commit

Permalink
🛠 Fix up benchmarks (still need to finish error handler ones...)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Jan 9, 2024
1 parent d34d4d0 commit bba2e92
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 60 deletions.
51 changes: 7 additions & 44 deletions benchmarks/barrier/include/barrier/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,60 +69,23 @@ ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_data
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_basic_source_data;


ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_unicode_error_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_unicode_error_data;

ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_basic_source_error_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_basic_source_error_data;

ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_unicode_error_replacement_u003a_expected_data;
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_ascii_replacement_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_replacement_u003a_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_unicode_error_replacement_u003a_expected_data;

ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_basic_source_error_replacement_u003a_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_replacement_u003a_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_basic_source_error_replacement_u003a_expected_data;

ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_unicode_replacement_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_unicode_error_replacement_ufffd_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_replacement_ufffd_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_unicode_error_replacement_ufffd_expected_data;

ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_basic_source_error_replacement_ufffd_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_replacement_ufffd_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_basic_source_error_replacement_ufffd_expected_data;

ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_unicode_error_skip_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_skip_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_unicode_error_skip_expected_data;

ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_unicode_error_no_replacement_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_basic_source_error_skip_expected_data;
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_ascii_replacement_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_skip_expected_data;
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_unicode_replacement_expected_data;
ZTD_C_LANGUAGE_LINKAGE_I_
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char32_t u32_basic_source_error_skip_expected_data;
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char16_t u16_basic_source_error_no_replacement_expected_data;

#endif
1 change: 0 additions & 1 deletion benchmarks/barrier/source/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <ztd/tests/basic_unicode_strings.hpp>

#include <vector>
#include <stdexcept>

static auto init_u8_unicode_data() {
std::vector<ztd_char8_t> data;
Expand Down
120 changes: 120 additions & 0 deletions benchmarks/barrier/source/data_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// ============================================================================
//
// ztd.text
// Copyright © JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: [email protected]
//
// Commercial License Usage
// Licensees holding valid commercial ztd.text licenses may use this file
// in accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact [email protected].
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ========================================================================= //

#include <barrier/data.h>

#include <barrier/barrier.h>

#include <ztd/cuneicode.h>
#include <ztd/idk/size.hpp>
#include <ztd/idk/c_span.h>
#include <ztd/idk/charN_t.hpp>
#include <ztd/idk/detail/unicode.h>

#include <ztd/tests/basic_unicode_strings.hpp>

#include <vector>

static auto init_u8_unicode_data() {
std::vector<ztd_char8_t> data;
data.reserve(static_cast<std::size_t>(__ztd_idk_detail_last_unicode_code_point * 3));
for (ztd_char32_t c = 0; c < __ztd_idk_detail_last_unicode_code_point; ++c) {
if (__ztd_idk_detail_is_surrogate(c)) {
continue;
}
ztd_char8_t output_buffer[6];
ztd_char8_t* output = output_buffer;
const ztd_char32_t* input = &c;
size_t input_size = 1;
size_t output_size = ztdc_c_array_size(output_buffer);
cnc_mcerr err = cnc_c32ntoc8n(&output_size, &output, &input_size, &input);
if (err != cnc_mcerr_ok) {
throw std::runtime_error("bad idea");
}
size_t written_output_size = ztdc_c_array_size(output_buffer) - output_size;
if (written_output_size > 4) {
throw std::runtime_error("bad idea");
}
for (std::size_t i = 0; i < written_output_size; ++i) {
data.push_back(output_buffer[i]);
}
}
return data;
}

static auto init_u16_unicode_data() {
std::vector<ztd_char16_t> data;
data.reserve(static_cast<std::size_t>(__ztd_idk_detail_last_unicode_code_point * 3));
for (ztd_char32_t c = 0; c < __ztd_idk_detail_last_unicode_code_point; ++c) {
if (__ztd_idk_detail_is_surrogate(c)) {
continue;
}
ztd_char16_t output_buffer[6];
ztd_char16_t* output = output_buffer;
const ztd_char32_t* input = &c;
size_t input_size = 1;
size_t output_size = ztdc_c_array_size(output_buffer);
cnc_mcerr err = cnc_c32ntoc16n(&output_size, &output, &input_size, &input);
if (err != cnc_mcerr_ok) {
throw std::runtime_error("bad idea");
}
size_t written_output_size = ztdc_c_array_size(output_buffer) - output_size;
if (written_output_size > 2) {
throw std::runtime_error("bad idea");
}
for (std::size_t i = 0; i < written_output_size; ++i) {
data.push_back(output_buffer[i]);
}
}
return data;
}
static auto init_u8_basic_source_data() {
std::vector<ztd_char8_t> data(
ztd::tests::u8_basic_source_character_set.cbegin(), ztd::tests::u8_basic_source_character_set.cend());
return data;
}

static auto init_u16_basic_source_data() {
std::vector<ztd_char16_t> data(
ztd::tests::u16_basic_source_character_set.cbegin(), ztd::tests::u16_basic_source_character_set.cend());
return data;
}

static auto u8_unicode_vec = init_u8_unicode_data();
static auto u8_basic_source_vec = init_u8_basic_source_data();
static auto u16_basic_source_vec = init_u16_basic_source_data();
static auto u16_unicode_vec = init_u16_unicode_data();


/*ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_unicode_data
= make_c_span_char8_t(u8_unicode_vec.data(), u8_unicode_vec.data() + u8_unicode_vec.size());
ZTD_TEXT_BENCHMARKS_BARRIER_API_LINKAGE_I_ c_span_char8_t u8_basic_source_data
= make_c_span_char8_t(u8_basic_source_vec.data(), u8_basic_source_vec.data() + u8_basic_source_vec.size());
*/
5 changes: 5 additions & 0 deletions benchmarks/conversion_speed/graph_config.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@
"pattern": "noop$",
"description": "Measures doing literally nothing (no written expressions/statements in the benchmarking loop). Can be useful for determining potential environment noise.",
"always_included": true
},
{
"name": "memcpy",
"pattern": "memcpy$",
"description": "Measures just copying the correct, expected data to the desired output. This is useful as a reflection of how fast it could potentially be."
}
],
"data_labels": [
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/conversion_speed/graph_config.internal.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@
"pattern": "noop$",
"description": "Measures doing literally nothing (no written expressions/statements in the benchmarking loop). Can be useful for determining potential environment noise.",
"always_included": true
},
{
"name": "memcpy",
"pattern": "memcpy$",
"description": "Measures just copying the correct, expected data to the desired output. This is useful as a reflection of how fast it could potentially be."
}
],
"data_labels": [
Expand Down
19 changes: 4 additions & 15 deletions benchmarks/conversion_speed/source/memcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,6 @@
state.SkipWithError("memcmp failed somehow???"); \
} \
} \
static void utf##FROM_N##_to_utf##TO_N##_well_formed_unchecked_memcpy(benchmark::State& state) { \
using to_char_t = ztd_char##TO_N##_t; \
std::vector<to_char_t> output_data(c_span_char##TO_N##_t_size(u##TO_N##_data)); \
bool result = true; \
for (auto _ : state) { \
std::memcpy(output_data.data(), c_span_char##TO_N##_t_data(u##TO_N##_data), \
output_data.size() * sizeof(*output_data.data())); \
} \
const bool is_equal \
= std::equal(output_data.cbegin(), output_data.cend(), c_span_char##TO_N##_t_data(u##TO_N##_data), \
c_span_char##TO_N##_t_data(u##TO_N##_data) + c_span_char##TO_N##_t_size(u##TO_N##_data)); \
if (!result) { \
state.SkipWithError("memcmp failed somehow???"); \
} \
} \
static_assert(true, "")

UTF_CONVERSION_BENCHMARK(8, 8);
Expand Down Expand Up @@ -113,6 +98,10 @@ BENCHMARK(utf16_to_utf8_well_formed_memcpy);
BENCHMARK(utf32_to_utf16_well_formed_memcpy);
BENCHMARK(utf32_to_utf8_well_formed_memcpy);

BENCHMARK(utf8_to_utf8_init_well_formed_memcpy);
BENCHMARK(utf16_to_utf16_init_well_formed_memcpy);
BENCHMARK(utf32_to_utf32_init_well_formed_memcpy);

BENCHMARK(utf8_to_utf16_init_well_formed_memcpy);
BENCHMARK(utf8_to_utf32_init_well_formed_memcpy);
BENCHMARK(utf16_to_utf32_init_well_formed_memcpy);
Expand Down

0 comments on commit bba2e92

Please sign in to comment.