请将以下golang语言代码转为js对应版本然我运行测试package mainimport fmt strings timefunc main start = timeNow str = hello world! for i = 0; i 10000000; i++ str = stringsReplaceAllstr o 0
const { performance } = require('perf_hooks');
function main() { const start = performance.now();
let str = "hello, world!"; for (let i = 0; i < 10000000; i++) { str = str.replace(/o/g, "0"); str = str.replace(/l/g, "1"); str = str.replace(/,/g, ""); str = str.replace(/!/g, ""); str = reverse(str); }
const end = performance.now(); console.log("JS程序运行时间:", end - start, "ms"); }
function reverse(s) { let runes = s.split(""); for (let i = 0, j = runes.length - 1; i < j; i++, j--) { [runes[i], runes[j]] = [runes[j], runes[i]]; } return runes.join(""); }
main()
原文地址: http://www.cveoy.top/t/topic/fqAA 著作权归作者所有。请勿转载和采集!