alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (bug4279.scala)

This example Scala source code file (bug4279.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, array, double, double, int, int, runner, runner, test, testutil, unit

The Scala bug4279.scala source code

import scala.tools.partest._

// Attempting to verify slice isn't 100,000x slower
// with views than non-views.
class Runner(num: Int, reps: Int) extends TestUtil {
  var dummy = 0
  val range = Array.range(0, num)
  
  def iteratorSlice = {
    def it = range.iterator.slice(num - 2, num)
    for (i <- 1 to reps)
      it foreach (dummy = _)
  }
  def viewSlice = {
    val view = range.view.slice(num - 2, num)
    for (i <- 1 to reps)
      view foreach (dummy = _)
  }
  def straightSlice = {
    val xs = range.slice(num - 2, num)
    for (i <- 1 to reps)
      xs foreach (dummy = _)
  }
  def run(multiple: Double) = {
    verifySpeed(straightSlice, iteratorSlice, multiple)
    verifySpeed(straightSlice, viewSlice, multiple)
  }
}

object Test {
  def main(args: Array[String]): Unit = {
    // warmup
    { val r = new Runner(1000000, 10) ; r.straightSlice ; r.iteratorSlice ; r.viewSlice }

    new Runner(10000000, 10) run 500
    new Runner(10000000, 50) run 300
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala bug4279.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.