Home > Web Front-end > JS Tutorial > Efficiency issues of javascript string splicing_javascript skills

Efficiency issues of javascript string splicing_javascript skills

WBOY
Release: 2016-05-16 18:13:34
Original
1101 people have browsed it
Copy code The code is as follows:

function xntest(){
var d1=new Date() ;
var str="";
for(var i=0;i<10000;i ){
str ="stext";
}
var d2=new Date() ;
document.write("String concatenation method takes time:" (d2.getTime()- d1.getTime()) "Milliseconds;");
d1=new Date();
var sb=new Array();
for(var i=0;i<10000;i ){
sb.push("stext");
}
var result=sb.toString( );
d2=new Date();
document.write(" Array method takes time: " (d2.getTime()- d1.getTime()) "Milliseconds;");
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template