We all tried the native replace function, to find that it only replace the first occurrence, and we have to use a regex to really replace all, like this: “the blue fox”.replace(/blue/g, “red”);
Now, the replaceAll does what we hope, by replacing all “string1” with “string2”, in the whole string instance, returning a copy of it.
But, in the meantime, lots of people tried to create their own replaceAll function, and one of them was to use the split / join trick. We found that it’s also very powerful when we need to manage large strings, or with a large amount of strings to convert.
So, I tried to see if I can replace all my split-join usage, with the new replaceAll. And, the answer is NO! Instead, I will make sure I never use the new replaceall, and I’ll keep my old custom function.
The split-join is, depending on the length of the input / find / replaceBy variables, up to 5 times faster in the tests I did. Sometimes, it’s the same speed, but most of the time, it’s faster. And, in Chrome 85, it’s never slower.
var i = 25;
var s = "asdf".repeat(i * 100000);
var sFrom = "sd";
var sTo = "z".repeat(i);
var t0 = (new Date()).getTime();
var t1 = s.replaceAll(sFrom, sTo);
console.log("t1", t1.length, (new Date()).getTime() - t0);
var t0 = (new Date()).getTime();
var t2 = s.split(sFrom).join(sTo);
console.log("t2", t2.length, (new Date()).getTime() - t0);
Look at these results: First 5 are “replace”, last 5 are “split/join”
replaceAll: 750ms split/join: 250ms
There’s no doubt that the split/join method is still the fastest.
But, if you need to use “regex” instead, now the replaceAll is the one to use.
I recently decided to move from Kobo to Kindle. Because I have a Prime subscription, that give free books, from their “Prime Reading” offer. Also because there was a good deal on Boxing Day, we could get it for only $60.
They call it the “All-New Kindle”, something like a new version of the previous Paper White I think, without water resistance…
To manage Kobo files, I always used the Adobe Digital Editions software, who works great, fast and easy to use. It is compatible with all e-readers in the world, except Kindle.
Then, I thought Amazon did an app like that. They did an app called Send To Kindle, works really find with pdf and some other formats, but not Epub files.
So, after a few research, you found that Calibre app, that can help you copy these files to your Kindle.
I tried it. Added my Epub to the library, and hit the “send to device” button. What? That is terribly slow, and it crashed a lot of times. I thought, like others on the internet, that the kindle device or its USB port is so so slow and that’s the reason calibre is slow.
But, the problem is not the kindle. It’s calibre!
The good way to send your Epub to kindle, using the Calibre app, is to do a 2-step process.
First, select your files, click “Convert”, and choose “Mobi” format on the top right dropdown.
Then, wait. And wait again. That process is very long.
When it’s complete, select all your files again, and now hit Send to Device button. Now, it will be very fast without crashing.
I think Calibre have lots of trouble handing conversion + usb transfert at the same time.
You can see the running jobs by clicking the “Jobs” label on the lower right corner of Calibre app.
Now, restart your Kindle device, you will see all your uploaded content appear one by one for about a minute.
That said, Calibre is an easy to use, free well done app, that help us get control over Kindle devices. That’s why all Calibre users should hit the “Support Calibre” link and donate something, to encourage that developer to continue supporting that app for a long time.