Interesting test for unique string processing

66 views
Skip to first unread message

Arlen Beiler

unread,
Dec 29, 2020, 7:36:08 PM12/29/20
to TiddlyWiki
Here is an interesting test to see which method of unique strings is faster in Javascript. Paste it into your browser console in a new tab and see what happens.

for (let r = 0; r < 100; r++) {
let test = Math.random().toExponential(10);
let count = 1000;
let test1 = {};
let test2 = [];
console.time("test 1");
for (let i = 0; i < count; i++) {
let item = test + "" + i;
if (!test1[item]) test1[item] = true;
}
console.timeEnd("test 1");
console.time("test 2");
for (let i = 0; i < count; i++) {
let item = test + "" + i;
if (test2.indexOf(item) === -1) test2.push(item);
}
console.timeEnd("test 2");
}

TW Tones

unread,
Dec 29, 2020, 9:49:21 PM12/29/20
to TiddlyWiki
Hi,

If you are proposing this be used in the core or such perhaps it would be better to raise this in the developer discussion's. Since as a rule Javascript is not native in User interface but provides modules and plugins.


tones

PMario

unread,
Jan 1, 2021, 10:58:24 AM1/1/21
to TiddlyWiki
Hi Arlen,
It would be interesting, what you try to prove here?

Accessing big arrays with a loop is probably always slower than accessing an object element by name. The biggest difference probably is memory consumption.

-m
Reply all
Reply to author
Forward
0 new messages