Skip to content

Instantly share code, notes, and snippets.

@cyberdude
Created March 18, 2020 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberdude/65a8406532442bfc860cb9b69e69ce87 to your computer and use it in GitHub Desktop.
Save cyberdude/65a8406532442bfc860cb9b69e69ce87 to your computer and use it in GitHub Desktop.
replace http
var iterations = 100000;
const urls = [
"http://fast-die.kiev.ua/",
"http://www.shram.kiev.ua/",
"http://fei.ru/",
"https://psyplants.info/",
"https://www.pictureview.com/",
"http://abclider.com/",
"http://borgie.net/",
"http://diplomaticsecondpassport.com/",
"http://go-krit.com/",
"http://liability-insurance-company.com/",
"http://seedjah.com/",
"http://video-one.com/",
"http://www.weedy.be/",
"https://jahforum.org/",
"http://www.bbc.com/kyrgyz/",
"http://www.bbckyrgyz.com/",
"http://birdamlik.info/",
"http://fromuz.com/",
"http://www.centrasia.ru/",
"https://eltuz.com/",
"http://ca-news.org/",
"http://harakat.net/",
"http://uzxalqharakati.com/",
"http://www.asiaterra.info/",
"http://www.fergananews.com/",
"http://www.uzmetronom.com/",
"https://centre1.com/",
"https://jahonnoma.com/",
"https://rus.ozodlik.org/",
"https://turonzamin.org/",
"https://www.golos-ameriki.ru/",
"http://fikr.uz/",
"https://kun.uz/",
"https://uzreport.uz/",
"https://kk.wikipedia.org/"
];
const basePaser = fn => urls.forEach(url => fn(url));
const functionOne = () => {
basePaser(url => url.replace(/^http:\/\//, "https://"));
};
const functionTwo = () => {
basePaser(url => url.replace("http://", "https://"));
};
const functionThree = () => {
basePaser(url =>
url.startsWith("http://") ? "https".concat(url.slice(4)) : url
);
};
console.time("regex #1");
for (var i = 0; i < iterations; i++) {
functionOne();
}
console.timeEnd("regex #1");
console.time("String replace #2");
for (var i = 0; i < iterations; i++) {
functionTwo();
}
console.timeEnd("String replace #2");
console.time("Function currect fix func #3");
for (var i = 0; i < iterations; i++) {
functionThree();
}
console.timeEnd("Function currect fix func #3");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment