1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "minikin/Hyphenator.h" 17 18 #include <benchmark/benchmark.h> 19 20 #include "FileUtils.h" 21 #include "UnicodeUtils.h" 22 23 namespace minikin { 24 25 const char* enUsHyph = "/system/usr/hyphen-data/hyph-en-us.hyb"; 26 const int enUsMinPrefix = 2; 27 const int enUsMinSuffix = 3; 28 29 static void BM_Hyphenator_short_word(benchmark::State& state) { 30 Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data(), enUsMinPrefix, 31 enUsMinSuffix, "en"); 32 std::vector<uint16_t> word = utf8ToUtf16("hyphen"); 33 std::vector<HyphenationType> result; 34 while (state.KeepRunning()) { 35 hyphenator->hyphenate(word, &result); 36 } 37 } 38 39 // TODO: Use BENCHMARK_CAPTURE for parametrise. 40 BENCHMARK(BM_Hyphenator_short_word); 41 42 static void BM_Hyphenator_long_word(benchmark::State& state) { 43 Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data(), enUsMinPrefix, 44 enUsMinSuffix, "en"); 45 std::vector<uint16_t> word = utf8ToUtf16("Pneumonoultramicroscopicsilicovolcanoconiosis"); 46 std::vector<HyphenationType> result; 47 while (state.KeepRunning()) { 48 hyphenator->hyphenate(word, &result); 49 } 50 } 51 52 // TODO: Use BENCHMARK_CAPTURE for parametrise. 53 BENCHMARK(BM_Hyphenator_long_word); 54 55 // TODO: Add more tests for other languages. 56 57 } // namespace minikin 58