parseIntTest.frink

Download or view parseIntTest.frink in plain text format


/** This tests parsing of integers, formatting of integers to strings, and
    round-tripping. */

parseIntTest[str] :=
{
   s1=now[];n=parseInt[str];e1=now[]; println["Parse:    " + format[e1-s1, "ms", 0]]
   s2=now[];r=toString[n];e2=now[];   println["toString: " + format[e2-s2, "ms", 0]]
   if (e2-s2) != 0 s
      println["Ratio:    " + format[(e1-s1)/(e2-s2), 1, 3]]
   if r != str
      println["**** Error: $r, $str"]
   
   return e1-s1
}

lastTime = undef
for i=1 to 7
{
   n = -(10^(10^i) - 1)
   str = toString[n]
   time = parseIntTest[str]
   
   print["Time to parse " + length[str] + " digits:\t" + format[time, "ms", 0]]
   
   if lastTime != undef  && lastTime > 0 s && time > 0 s
   {
      order = log[time/lastTime] / log[10]
      println["\tO(n^" + format[order, 1, 3] + ")"]
   } else
      println[]

   lastTime = time
}


Download or view parseIntTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19972 days, 6 hours, 52 minutes ago.