()
| 40 | } |
| 41 | |
| 42 | async function run() { |
| 43 | const bench = new Bench({time: 1000}) |
| 44 | |
| 45 | bench |
| 46 | .add( |
| 47 | 'segment_cached_grapheme_collect_all', |
| 48 | () => |
| 49 | collectSegments(cachedSegmenters.grapheme.segment(inputString)).length |
| 50 | ) |
| 51 | .add( |
| 52 | 'segment_cached_word_collect_all', |
| 53 | () => collectSegments(cachedSegmenters.word.segment(inputString)).length |
| 54 | ) |
| 55 | .add( |
| 56 | 'segment_cached_sentence_collect_all', |
| 57 | () => |
| 58 | collectSegments(cachedSegmenters.sentence.segment(inputString)).length |
| 59 | ) |
| 60 | //@ts-ignore |
| 61 | .add('segment_cached_grapheme_containing', () => { |
| 62 | return cachedSegmenters.grapheme |
| 63 | .segment(inputString) |
| 64 | .containing(Math.floor(Math.random() * inputString.length)) |
| 65 | }) |
| 66 | .add('segment_cached_word_containing', () => |
| 67 | cachedSegmenters.word |
| 68 | .segment(inputString) |
| 69 | .containing(Math.floor(Math.random() * inputString.length)) |
| 70 | ) |
| 71 | .add('segment_cached_sentence_containing', () => |
| 72 | cachedSegmenters.sentence |
| 73 | .segment(inputString) |
| 74 | .containing(Math.floor(Math.random() * inputString.length)) |
| 75 | ) |
| 76 | .add( |
| 77 | 'new_segmenter_grapheme', |
| 78 | () => new Segmenter(locale, {granularity: 'grapheme'}) |
| 79 | ) |
| 80 | .add( |
| 81 | 'new_segmenter_word', |
| 82 | () => new Segmenter(locale, {granularity: 'word'}) |
| 83 | ) |
| 84 | .add( |
| 85 | 'new_segmenter_sentence', |
| 86 | () => new Segmenter(locale, {granularity: 'sentence'}) |
| 87 | ) |
| 88 | |
| 89 | await bench.run() |
| 90 | |
| 91 | console.table(bench.table()) |
| 92 | } |
| 93 | |
| 94 | run() |
| 95 |
no test coverage detected