var _StopWatch = new StopWatch(); _StopWatch.start(); var maxSubStrings = 1024000; var strs = new Array(maxSubStrings); for (i=0; i<maxSubStrings ; i++) { strs[i] = i + " "; } _StopWatch.stop(); document.write("Time creating string array of size " + maxSubStrings + ": " + _StopWatch.duration() + " seconds<br/>"); _StopWatch.start(); var strConcated = ""; for (i=0; i<maxSubStrings ; i++) { strConcated += strs[i]; } _StopWatch.stop(); document.write("Time concating strings from array: " + _StopWatch.duration() + " seconds<br/>"); _StopWatch.start(); var strConcated = ""; for (i=0; i<maxSubStrings ; i++) { strConcated = strConcated.concat(strs[i]); } _StopWatch.stop(); document.write("Time concating strings from array using concat(): " + _StopWatch.duration() + " seconds<br/>") _StopWatch.start(); var strJoined = strs.join(); _StopWatch.stop(); document.write("Time joining strings from array: " + _StopWatch.duration() + " seconds<br/>"); function sleep(ms) { var timer = new Date(); var time = timer.getTime(); do timer = new Date(); while( (timer.getTime() - time) < ms); } // StopWatch written by MCF.Goodwin from http://www.codeproject.com/Articles/29330/JavaScript-Stopwatch function StopWatch() { var startTime = null; var stopTime = null; var running = false; this.start = function () { if (running == true) return; else if (startTime != null) stopTime = null; running = true; startTime = getTime(); } this.stop = function () { if (running == false) return; stopTime = getTime(); running = false; } this.duration = function () { if (startTime == null || stopTime == null) return 'Undefined'; else return (stopTime - startTime) / 1000; } this.isRunning = function () { return running; } function getTime() { var day = new Date(); return day.getTime(); } }