vectorTiming.frink

Download or view vectorTiming.frink in plain text format


// This file tests timing differences in vector math vs. iterative
// calculations.

size = million

a = new array[size]
b = new array[size]

for i = 1 to size
{
   a.push[randomFloat[1,1000]]
   b.push[randomFloat[1,1000]]
}

println["Done generating."]

for iter = 1 to 10
{
   d = new array
   s = now[]
   for i=0 to size-1
      d@i = a@i * b@i
   e = now[]
   println["Iterative multiply time: " + format[e-s, "s", 3]]

   s = now[]
   c = a * b
   e = now[]
   println["Vector multiply time: " + format[e-s, "s", 3]]

   if d != c
      println["***Mismatch!"]
}


Download or view vectorTiming.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 19944 days, 9 hours, 17 minutes ago.