Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid benchmark (and memory leak) #10

Open
ku8ar opened this issue Jul 31, 2020 · 1 comment
Open

invalid benchmark (and memory leak) #10

ku8ar opened this issue Jul 31, 2020 · 1 comment

Comments

@ku8ar
Copy link

ku8ar commented Jul 31, 2020

This library has a built-in cache, so any comparison to other libraries or native functions is useless and the documentation is misleading for developers.
Please correct the documentation and include information about the cache, which can be dangerous in some situations.

@jimmywarting
Copy link

yep, repeat-string have an unfair advantage in there bench test.
they don't show/compare the time it takes to do it just 1 time cuz it only looks bad in their bench result
...or when the cache is disabled (as in using different strings every time you call the repeat function)

here are some result of just comparing the raw power of using native vs repeat-string (\w cache turned off)

async function code1() {
  const mod = await import('https://jspm.dev/repeat-string')
  const repeat = mod.default
  
  const str1 = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
  
  const str2 = `It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).`

  let i = 100_000
  console.time('repeat-string')
  while(i--) {
    repeat(str1, 10)
    repeat(str2, 10) // to clear cache
  }
  console.timeEnd('repeat-string')
}

async function code2() {
  const str1 = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
  
  const str2 = `It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).`

  let i = 100_000
  console.time('native')
  while(i--) {
    str1.repeat(10)
    str2.repeat(10)
  }
  console.timeEnd('native')
}

const blob1 = new Blob([code1.toString() + ';code1()'], { type: 'text/javascript' })
const blob2 = new Blob([code2.toString() + ';code2()'], { type: 'text/javascript' })

new Worker(URL.createObjectURL(blob2), { type: 'module'})
new Worker(URL.createObjectURL(blob1), { type: 'module'})

Chrome: 104
native: 6.642822265625 ms
repeat-string: 8.089111328125 ms

Safari: 15.6
native: 17.117 ms
repeat-string: 19.190 ms


Honestly you don't need any repeat library just use built in String.prototype.repeat instead... it's fast enough and don't leak anything. it probably also have smarter internal ways to make a variable repeat n number of times that are more memory efficient

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

No branches or pull requests

2 participants