progs/bfc0.scala
changeset 636 96a91e4a8ac8
parent 634 2c46407af618
child 637 27f71d2755f0
equal deleted inserted replaced
635:7c2c0f10c424 636:96a91e4a8ac8
    44   //println(is)
    44   //println(is)
    45   fw.write(is) 
    45   fw.write(is) 
    46   fw.close()
    46   fw.close()
    47 }
    47 }
    48 
    48 
       
    49 // running the c-compiler over the transpiled
       
    50 // BF program and running the result
    49 import sys.process._
    51 import sys.process._
    50 
    52 
    51 def compile_run(prog: String) = {
    53 def compile_run(prog: String) = {
    52   compile("tmp", prog)
    54   compile("tmp", prog)
    53   "gcc -O0 -o tmp tmp.c".!
    55   "gcc -O0 -o tmp tmp.c".!
    60   for (i <- 0 until n) code
    62   for (i <- 0 until n) code
    61   val end = System.nanoTime()
    63   val end = System.nanoTime()
    62   (end - start)/(n * 1.0e9)
    64   (end - start)/(n * 1.0e9)
    63 }
    65 }
    64 
    66 
       
    67 // mandelbrot program
       
    68 val b0 = load_bff("mandelbrot.bf")
    65 
    69 
    66 println(s"${time_needed(1, compile_run(load_bff("mandelbrot.bf")))} secs")
    70 println(s"${time_needed(1, compile_run(b0))} secs")
    67 
    71 
    68 
    72 
    69 
    73 
    70 // a benchmark program (counts down from 'Z' to 'A')
    74 // a benchmark program (counts down from 'Z' to 'A')
    71 val b1 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
    75 val b1 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++