Re: Create a string with (n) copies of the same character



Dr J R Stockton wrote on 20 sep 2007 in
microsoft.public.scripting.jscript:

function BigCat(L) {
if (!L) return ""
if (L&1) return BigCat(L-1) + "x"
var T = BigCat(L/2) ; return T + T }


what about:

L>>1

for

L/2

?

In itself it seems to be at least 3 times as fast:

==================================
<script type='text/javascript'>

function f1(n){
for (var i=0;i<n;i++)
z = 555550/2
};

function f2(n){
for (var i=0;i<n;i++)
z = 555550>>1
};

function f3(n){
for (var i=0;i<n;i++)
z = 7
};

var n = 600000

var t = new Date();
f3(n);
var overhead = new Date()-t

t = new Date();
f1(n);
document.write( new Date()-t-overhead + '<br>');

t = new Date();
f2(n);
document.write( new Date()-t-overhead + '<br>');

</script>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.



Relevant Pages

  • Re: Select, Option, innerHTML,Internet Explorer, Firefox, bug
    ... If you go back to last century you'll find that several popular web ... I use var U within a routine that needs it. ... The essential point is that it should NOT be any English word. ... John Stockton, nr London, UK. ...
    (comp.lang.javascript)
  • Re: Comparing Strings
    ... var re = new RegExp; ... The Netherlands. ... (Please change the x'es to dots in my emailaddress) ...
    (comp.lang.javascript)
  • Re: ECMAStript 4, Re: Upcoming Changes to the JavaScript Language
    ... Dr J R Stockton wrote on 05 dec 2007 in comp.lang.javascript: ... alternatives to punctuation marks in B? ... var A = B .then. ... (Please change the x'es to dots in my emailaddress) ...
    (comp.lang.javascript)
  • Re: monthly frames
    ... prophet wrote on 21 sep 2006 in comp.lang.javascript: ... var s = ... (Please change the x'es to dots in my emailaddress) ...
    (comp.lang.javascript)
  • Re: Desperately need help - PLEASE!
    ... Dr J R Stockton wrote on 08 sep 2007 in comp.lang.javascript: ... var tomorrow = now; ... (Please change the x'es to dots in my emailaddress) ...
    (comp.lang.javascript)

Loading