| 1 | /* Copyright (c) 2016, 2026, Oracle and/or its affiliates. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License, version 2.0, |
| 5 | as published by the Free Software Foundation. |
| 6 | |
| 7 | This program is designed to work with certain software (including |
| 8 | but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | as designated in a particular file or component or in included license |
| 10 | documentation. The authors of MySQL hereby grant you an additional |
| 11 | permission to link the program and your derivative works with the |
| 12 | separately licensed software that they have either included with |
| 13 | the program or referenced in the documentation. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License, version 2.0, for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | #include "m_ctype.h" |
| 27 | #include "my_inttypes.h" |
| 28 | #include "my_sys.h" |
| 29 | #include "unittest/gunit/benchmark.h" |
| 30 | |
| 31 | namespace strings_valid_check_unittest { |
| 32 | // Benchmark testing character valid check function of utf8 charset |
| 33 | static void BM_UTF8_Valid_Check(size_t num_iterations) { |
| 34 | StopBenchmarkTiming(); |
| 35 | |
| 36 | const char *content = |
| 37 | "MySQL は 1億以上のダウンロード数を誇る、世界" |
| 38 | "でもっとも普及しているオープンソースデータベースソフトウェアです。" |
| 39 | "抜群のスピードと信頼性、使いやすさが備わった MySQL は、ダウンタイム" |
| 40 | "、メンテナンス、管理、サポートに関するさまざまな問題を解決することが" |
| 41 | "できるため、Web、Web2.0、SaaS、ISV、通信関連企業の 先見的なIT 責任者" |
| 42 | "の方々から大変な好評を博しています。"; |
| 43 | const int len = strlen(content); |
| 44 | MY_CHARSET_LOADER loader; |
| 45 | const CHARSET_INFO *cs = |
| 46 | my_collation_get_by_name(&loader, "utf8mb4_0900_ai_ci", MYF(0)); |
| 47 | int error = 0; |
| 48 | |
| 49 | StartBenchmarkTiming(); |
| 50 | for (size_t i = 0; i < num_iterations; ++i) { |
| 51 | cs->cset->well_formed_len(cs, content, content + len, len, &error); |
| 52 | } |
| 53 | StopBenchmarkTiming(); |
| 54 | |
| 55 | ASSERT_EQ(0, error); |
| 56 | } |
| 57 | BENCHMARK(BM_UTF8_Valid_Check) |
| 58 | |
| 59 | } // namespace strings_valid_check_unittest |