jprichardson / string.js

Extra JavaScript string methods.
http://stringjs.com
1.81k stars 233 forks source link

Using prototypes is slow #214

Open ghost opened 6 years ago

ghost commented 6 years ago

I did a benchmark test, and it turns out using prototypes makes a function call twice slower in Google Chrome, and in Firefox, it is 4-5 times slower!!! So, when you're writing a function library for strings where speed is of concern, then you should declare functions like this :

function truncate(str, length, pruneStr) { ... } // this is just an example

DO NOT USE PROTOTYPES. They needlessly slow down the execution of your code!

ghost commented 6 years ago

There's an alternative library that doesn't use prototypes. http://wzsn.net/zLib.htm