Skip to content

Commit

Permalink
feat: add benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball12 committed Aug 6, 2022
1 parent dc9660f commit 977e008
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
apps/benchmark
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -32,6 +32,21 @@ An Open-Source JavaScript Implementation of [Bionic Reading API](https://bionic-
| ------- | ------------------------------------------------------- |
| Saccade | [#21](https://github.com/Gumball12/text-vide/issues/21) |

### Benchmark

```
Sun Aug 07 2022 01:33:40 GM +0900
length of normal text: 590
length of text with html tags: 1579
normal#ignoreHtmlTags x 46,106 ops/sec ±4.22% (86 runs sampled)
normal#notIgnoreHtmlTags x 53,200 ops/sec ±0.93% (89 runs sampled)
withHtmlTags#ignoreHtmlTags x 3,213 ops/sec ±0.92% (87 runs sampled)
withHtmlTags#notIgnoreHtmlTags x 3,605 ops/sec ±1.59% (87 runs sampled)
```

[code](./apps/benchmark/index.js)

## ⚙️ Install

```bash
Expand Down
55 changes: 55 additions & 0 deletions apps/benchmark/index.js
@@ -0,0 +1,55 @@
const { textVide } = require('text-vide');
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();

const text =
'orem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';

const textWithHtmlTags = `<div class="bionic-reader-container">
<span class="w bionic"><b class="b bionic">nor</b>mal </span><span class="w bionic"><b class="b bionic">te</b>xt</span>: <span class="w bionic"><b class="b bionic">abcd</b>efg</span><br><span class="w bionic"><b class="b bionic">wi</b>th </span><span class="w bionic"><b class="b bionic">a</b> </span><span class="w bionic"><b class="b bionic">t</b>ag</span>: <a target="_blank"><span class="w bionic"><b class="b bionic">ab</b>cd</span></a><span class="w bionic"><b class="b bionic">e</b>fg</span><br><span class="w bionic"><b class="b bionic">wi</b>th </span><span class="w bionic"><b class="b bionic">b</b> </span><span class="w bionic"><b class="b bionic">t</b>ag</span>: <b><span class="w bionic"><b class="b bionic">ab</b>cd</span></b><span class="w bionic"><b class="b bionic">e</b>fg</span><br><span class="w bionic"><b class="b bionic">wi</b>th </span><span class="w bionic"><b class="b bionic">d</b>iv </span><span class="w bionic"><b class="b bionic">t</b>ag</span>: <div><span class="w bionic"><b class="b bionic">ab</b>cd</span></div><span class="w bionic"><b class="b bionic">e</b>fg</span><br>
<!-- <div class="br-foot-node">
<p style="margin: 32px 0 32px 70px; font-weight: 700; font-size: 26px; line-height: 1.6em;">
</p>
<p>
Bionic Reading<sup>®</sup><br>
A higher dimension of reading.<br>
<a href="https://bionic-reading.com">bionic-reading.com</a>
</p>
<br/>
<br/>
<p>
</p>
</div> -->
</div>`;

suite
.add('normal#ignoreHtmlTags', () => textVide(text))
.add('normal#notIgnoreHtmlTags', () =>
textVide(text, { ignoreHtmlTag: false }),
)

.add('withHtmlTags#ignoreHtmlTags', () => textVide(textWithHtmlTags))
.add('withHtmlTags#notIgnoreHtmlTags', () =>
textVide(textWithHtmlTags, { ignoreHtmlTag: false }),
)

.on('start', () =>
console.log(
[
new Date().toString(),
`length of normal text: ${text.length}`,
`length of text with html tags: ${textWithHtmlTags.length}`,
'',
].join('\n'),
),
)
.on('cycle', evt => {
console.log(evt.target.toString());
})
.run({ async: true });
11 changes: 11 additions & 0 deletions apps/benchmark/package.json
@@ -0,0 +1,11 @@
{
"name": "benchmark",
"version": "0.0.0",
"scripts": {
"benchmark": "node index.js"
},
"devDependencies": {
"benchmark": "^2.1.4",
"text-vide": "workspace:*"
}
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"dev": "turbo run dev --no-cache --parallel --continue",
"preview": "turbo run preview",
"test": "turbo run test",
"benchmark": "turbo run benchmark",
"release": "turbo run release",
"lint": "eslint --ext .ts ./**/src/**.ts",
"prepare": "husky install"
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions turbo.json
Expand Up @@ -18,6 +18,9 @@
"test": {
"cache": false
},
"benchmark": {
"outputs": []
},
"release": {
"cache": false
}
Expand Down

0 comments on commit 977e008

Please sign in to comment.