/** File "Timing.java" by KWR for CSE250, Spring 2022. Illustrates use of Java System.nanoTime */ public class Timing { public static void main(String[] args) { double ms = 1000000.0 double t1 = System.nanoTime() //var arr = Array.tabulate(1000000)(i => i) ArrayBuffer arr = new ArrayBuffer.fill(1000000)(7) double t2 = System.nanoTime() //var lst = List.tabulate(1000000)(i => i) List lst = new List.fill(1000000)(7) double t3 = System.nanoTime() println(s"\nCreation times (ms): array ${(t2 - t1)/ms}, list ${(t3 - t2)/ms}") println("\nJust to time prepending an element to each") double t4 = System.nanoTime() arr +:= -1 double t5 = System.nanoTime() lst +:= -1 double t6 = System.nanoTime() println(s"Prepend times (ms): array ${(t5 - t4)/ms}, list ${(t6 - t5)/ms}") println("\nHow about appending an element to each---") double t7 = System.nanoTime() arr :+= 1000000 double t8 = System.nanoTime() lst :+= 1000000 double t9 = System.nanoTime() println(s"Append times (ms): array ${(t8 - t7)/ms}, list ${(t9 - t8)/ms}") println("\nNow time to prepend onto a fresh array or list:") double t10 = System.nanoTime() var arr2 = -8 +: arr double t11 = System.nanoTime() var lst2 = -8 +: lst double t12 = System.nanoTime() println(s"Update times (ms): array ${(t11 - t10)/ms}, list ${(t12 - t11)/ms}") }