Skip to content

Latest commit

 

History

History
403 lines (298 loc) · 7.45 KB

README.md

File metadata and controls

403 lines (298 loc) · 7.45 KB

@napi-rs/hexo-util · License: MIT https://github.com/liby/hexo-util-rs/actions NPM version

Note

Utilities for Hexo. Generated from napi-rs/package-template.

Warning

This project is in alpha stage. And there may some bugs existed.

Installation

$ npm install @sukka/hexo-util-rs
// or
$ yarn add @sukka/hexo-util-rs
// or
$ pnpm add @sukka/hexo-util-rs

Usage

const util = require('@sukka/hexo-util-rs');

Performance

See benchmark for benchmark code.

Hardware info:

System Version: macOS 12.4 (21F79)
Kernel Version: Darwin 21.5.0
Processor Name: 8-Core Intel Core i9
Processor Speed: 2.3 GHz
L2 Cache (per Core): 256 KB
L3 Cache: 16 MB![img.png](img.png)
Memory: 32 GB

Benchmark:

Strip HTML
❯ yarn bench
Running "mini fixture" suite...
Progress: 100%

  hexo-util-rs-buffer:
    1 343 399 ops/s, ±0.55%   | 12.9% slower

  hexo-util-rs:
    1 542 449 ops/s, ±0.44%   | fastest

  hexo-util:
    933 979 ops/s, ±1.30%     | 39.45% slower

  striptags:
    466 526 ops/s, ±1.55%     | 69.75% slower

  string-strip-html:
    13 805 ops/s, ±11.48%      | slowest, 99.1% slower

Finished 5 cases!
  Fastest: hexo-util-rs
  Slowest: string-strip-html
Running "large fixture" suite...
Progress: 100%

  hexo-util-rs-buffer:
    816 ops/s, ±2.62%   | fastest

  hexo-util-rs:
    631 ops/s, ±3.68%   | 22.67% slower

  hexo-util:
    285 ops/s, ±4.13%   | 65.07% slower

  striptags:
    141 ops/s, ±1.45%   | 82.72% slower

  string-strip-html:
    7 ops/s, ±8.74%     | slowest, 99.14% slower

Finished 5 cases!
  Fastest: hexo-util-rs-buffer
  Slowest: string-strip-html
Slugify
❯ yarn bench
Running "slugify and escape diacritic" suite...
Progress: 100%

  hexo-util-rs:
    1 104 153 ops/s, ±0.30%   | fastest

  hexo-util:
    255 709 ops/s, ±0.61%     | slowest, 76.84% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
isExternalLink
❯ yarn bench
Running "Internal absolute url" suite...
Progress: 50%

  hexo-util-rs:
    1 038 833 ops/s, ±0.37% 
Progress: 100%

  hexo-util-rs:
    1 038 833 ops/s, ±0.37%   | fastest

  hexo-util:
    214 596 ops/s, ±0.30%     | slowest, 79.34% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "External absolute url" suite...
Progress: 50%

  hexo-util-rs:
    953 787 ops/s, ±0.41% 
Progress: 100%

  hexo-util-rs:
    953 787 ops/s, ±0.41%   | fastest

  hexo-util:
    203 306 ops/s, ±0.45%   | slowest, 78.68% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Relative absolute url" suite...
Progress: 50%

  hexo-util-rs:
    42 956 520 ops/s, ±0.87% 
Progress: 100%

  hexo-util-rs:
    42 956 520 ops/s, ±0.87%   | fastest

  hexo-util:
    18 071 147 ops/s, ±0.63%   | slowest, 57.93% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Encode URL
❯ yarn bench
Running "Encode URL - auth" suite...
Progress: 50%

  hexo-util-rs:
    1 299 520 ops/s, ±0.86% 
Progress: 100%

  hexo-util-rs:
    1 299 520 ops/s, ±0.86%   | fastest

  hexo-util:
    255 364 ops/s, ±0.92%     | slowest, 80.35% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Encode URL - Internationalized domain name" suite...
Progress: 50%

  hexo-util-rs:
    599 196 ops/s, ±0.87% 
Progress: 100%

  hexo-util-rs:
    599 196 ops/s, ±0.87%   | fastest

  hexo-util:
    177 869 ops/s, ±1.89%   | slowest, 70.32% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Encode URL - path with unicode" suite...
Progress: 50%

  hexo-util-rs:
    1 348 834 ops/s, ±1.38% 
Progress: 100%

  hexo-util-rs:
    1 348 834 ops/s, ±1.38%   | fastest

  hexo-util:
    1 111 192 ops/s, ±7.06%   | slowest, 17.62% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Decode URL
❯ yarn bench
Running "Decode URL - regular" suite...
Progress: 50%

  hexo-util-rs:
    1 632 744 ops/s, ±0.75% 
Progress: 100%

  hexo-util-rs:
    1 632 744 ops/s, ±0.75%   | fastest

  hexo-util:
    272 866 ops/s, ±1.70%     | slowest, 83.29% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Decode URL - path with space" suite...
Progress: 50%

  hexo-util-rs:
    2 630 212 ops/s, ±1.67% 
Progress: 100%

  hexo-util-rs:
    2 630 212 ops/s, ±1.67%   | fastest

  hexo-util:
    1 959 248 ops/s, ±0.72%   | slowest, 25.51% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Decode URL - space" suite...
Progress: 50%

  hexo-util-rs:
    1 228 376 ops/s, ±6.64% 
Progress: 100%

  hexo-util-rs:
    1 228 376 ops/s, ±6.64%   | fastest

  hexo-util:
    239 213 ops/s, ±1.72%     | slowest, 80.53% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Decode URL - hash and query" suite...
Progress: 50%

  hexo-util-rs:
    781 550 ops/s, ±1.90% 
Progress: 100%

  hexo-util-rs:
    781 550 ops/s, ±1.90%   | fastest

  hexo-util:
    166 420 ops/s, ±1.78%   | slowest, 78.71% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "Decode URL - Internationalized domain name" suite...
Progress: 50%

  hexo-util-rs:
    492 862 ops/s, ±6.49% 
Progress: 100%

  hexo-util-rs:
    492 862 ops/s, ±6.49%   | fastest

  hexo-util:
    155 205 ops/s, ±1.46%   | slowest, 68.51% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Escape Diacritic
❯ yarn bench
Running "default" suite...
Progress: 50%

  hexo-util-rs:
    4 152 262 ops/s, ±1.20% 
Progress: 100%

  hexo-util-rs:
    4 152 262 ops/s, ±1.20%   | fastest

  hexo-util:
    2 334 729 ops/s, ±1.62%   | slowest, 43.77% slower

Finished 2 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Unescape HTML
❯ yarn bench
Running "mini fixture" suite...
Progress: 33%

  hexo-util-rs-buffer:
    996 155 ops/s, ±1.41% 
Progress: 67%

  hexo-util-rs-buffer:
    996 155 ops/s, ±1.41% 

  hexo-util-rs:
    1 188 802 ops/s, ±0.36% 
Progress: 100%

  hexo-util-rs-buffer:
    996 155 ops/s, ±1.41%     | 16.21% slower

  hexo-util-rs:
    1 188 802 ops/s, ±0.36%   | fastest

  hexo-util:
    677 794 ops/s, ±0.37%     | slowest, 42.99% slower

Finished 3 cases!
  Fastest: hexo-util-rs
  Slowest: hexo-util
Running "large fixture" suite...
Progress: 33%

  hexo-util-rs-buffer:
    30 402 ops/s, ±0.64% 
Progress: 67%

  hexo-util-rs-buffer:
    30 402 ops/s, ±0.64% 

  hexo-util-rs:
    27 585 ops/s, ±1.81% 
Progress: 100%

  hexo-util-rs-buffer:
    30 402 ops/s, ±0.64%   | fastest

  hexo-util-rs:
    27 585 ops/s, ±1.81%   | 9.27% slower

  hexo-util:
    15 185 ops/s, ±0.58%   | slowest, 50.05% slower

Finished 3 cases!
  Fastest: hexo-util-rs-buffer
  Slowest: hexo-util

License

MIT