Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Long attribute keys take a very long time to process #26

Open
brian-c opened this issue Nov 8, 2017 · 0 comments
Open

Long attribute keys take a very long time to process #26

brian-c opened this issue Nov 8, 2017 · 0 comments

Comments

@brian-c
Copy link

brian-c commented Nov 8, 2017

This code times a bunch of attribute keys:

const truncate = require('html-truncate');

function timeTruncate(html) {
    const start = Date.now();
    truncate(html, 0);
    const end = Date.now();
    console.log(`${end - start}ms for ${html}`)
}

timeTruncate('<div a="x"></div>');
timeTruncate('<div a00000009="x"></div>');
timeTruncate('<div a000000010="x"></div>');
timeTruncate('<div a0000000011="x"></div>');
timeTruncate('<div a00000000012="x"></div>');
timeTruncate('<div a000000000013="x"></div>');
timeTruncate('<div a0000000000014="x"></div>');
timeTruncate('<div a00000000000015="x"></div>');
timeTruncate('<div a000000000000016="x"></div>');
timeTruncate('<div a0000000000000017="x"></div>');
timeTruncate('<div a00000000000000018="x"></div>');
timeTruncate('<div a000000000000000019="x"></div>');
timeTruncate('<div a0000000000000000020="x"></div>');
timeTruncate('<div a00000000000000000021="x"></div>');
timeTruncate('<div a000000000000000000022="x"></div>');
timeTruncate('<div a0000000000000000000023="x"></div>');
timeTruncate('<div a00000000000000000000024="x"></div>');
timeTruncate('<div a000000000000000000000025="x"></div>');

The results, with html-truncate 1.2.2 and Node v8.9.0:

1ms for <div a="x"></div>
1ms for <div a00000009="x"></div>
0ms for <div a000000010="x"></div>
1ms for <div a0000000011="x"></div>
2ms for <div a00000000012="x"></div>
3ms for <div a000000000013="x"></div>
5ms for <div a0000000000014="x"></div>
12ms for <div a00000000000015="x"></div>
22ms for <div a000000000000016="x"></div>
34ms for <div a0000000000000017="x"></div>
67ms for <div a00000000000000018="x"></div>
122ms for <div a000000000000000019="x"></div>
230ms for <div a0000000000000000020="x"></div>
450ms for <div a00000000000000000021="x"></div>
880ms for <div a000000000000000000022="x"></div>
1828ms for <div a0000000000000000000023="x"></div>
4199ms for <div a00000000000000000000024="x"></div>
7585ms for <div a000000000000000000000025="x"></div>

Things start getting a little out of hand beyond ten characters.

Possibly related to #24?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant