Permalink
Browse files

Refactored load, created Model

  • Loading branch information...
1 parent 67e9cad commit 5b473a8abd55359e93a739cdef15c2924ebe2b0c @mslinn committed Mar 15, 2012
View
24 .gitignore 100644 → 100755
@@ -1,12 +1,12 @@
-.classpath
-executorBenchmark.properties
-*~
-.cache
-.idea/
-.idea_modules/
-.project
-.settings/
-*.iml
-*.stackdump
-project/target/
-target/
+.classpath
+executorBenchmark.properties
+*~
+.cache
+.idea/
+.idea_modules/
+.project
+.settings/
+*.iml
+*.stackdump
+project/target/
+target/
View
28 README.md 100644 → 100755
@@ -1,14 +1,14 @@
-Executor Benchmark
-===============================================
-
-Mike Slinn
-
-Google+: [mslinn](https://plus.google.com/115543354052259422614/posts)
-Twitter: [mslinn](https://twitter.com/#!/mslinn)
-
-[mslinn@micronauticsresearch.com](mailto:mslinn@micronauticsresearch.com)
-
-415-367-3789
-
-840 Main St #B2
-Half Moon Bay, CA 94019
+Executor Benchmark
+===============================================
+
+Mike Slinn
+
+Google+: [mslinn](https://plus.google.com/115543354052259422614/posts)
+Twitter: [mslinn](https://twitter.com/#!/mslinn)
+
+[mslinn@micronauticsresearch.com](mailto:mslinn@micronauticsresearch.com)
+
+415-367-3789
+
+840 Main St #B2
+Half Moon Bay, CA 94019
View
98 build.sbt
@@ -1,49 +1,49 @@
-// see https://github.com/sbt/sbt-assembly
-import AssemblyKeys._ // put this at the top of the file
-
-organization := "Micronautics Research"
-
-name := "executorBenchmark"
-
-version := "0.1"
-
-scalaVersion := "2.9.1-1"
-
-scalaVersion in update := "2.9.1"
-
-autoCompilerPlugins := true
-
-javaOptions in run += "-Xbatch -server -Xmx1G -Xms1G"
-
-resolvers ++= Seq(
- "Akka Snapshots" at "http://akka.io/snapshots",
- "Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots",
- "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
- "Scala-Tools Snapshots" at "http://scala-tools.org/repo-snapshots",
- "Scala Tools Releases" at "http://scala-tools.org/repo-releases",
- "Sonatype Nexus Releases" at "https://oss.sonatype.org/content/repositories/releases",
- "Sonatype Legacy Releases" at "https://oss.sonatype.org/content/repositories/releases",
- "Sonatype staging" at "https://oss.sonatype.org/content/repositories/staging",
- "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
-)
-
-libraryDependencies ++= Seq(
- "com.typesafe.akka" % "akka-actor" % "2.0" withSources(),
- "com.github.scala-incubator.io" % "scala-io-core_2.9.1" % "0.3.0" withSources(),
- "com.github.scala-incubator.io" % "scala-io-file_2.9.1" % "0.3.0" withSources(),
- "org.apache.httpcomponents" % "httpclient" % "4.1.2" withSources(),
- "org.scala-tools" % "scala-stm_2.9.1" % "0.5" withSources(),
- "org.scala-tools.time" % "time_2.9.1" % "0.5" ,
- "org.scala-lang" % "scala-swing" % "2.9.1-1" withSources(),
- "org.jfree" % "jfreechart" % "1.0.14" withSources()
-)
-
-seq(assemblySettings: _*)
-
-
-logLevel := Level.Error
-
-// Only show warnings and errors on the screen for compilations.
-// This applies to both test:compile and compile and is Info by default
-logLevel in compile := Level.Warn
-
+// see https://github.com/sbt/sbt-assembly
+import AssemblyKeys._ // put this at the top of the file
+
+organization := "Micronautics Research"
+
+name := "executorBenchmark"
+
+version := "0.1"
+
+scalaVersion := "2.9.1-1"
+
+scalaVersion in update := "2.9.1"
+
+autoCompilerPlugins := true
+
+javaOptions in run += "-Xbatch -server -Xmx1G -Xms1G"
+
+resolvers ++= Seq(
+ "Akka Snapshots" at "http://akka.io/snapshots",
+ "Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots",
+ "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
+ "Scala-Tools Snapshots" at "http://scala-tools.org/repo-snapshots",
+ "Scala Tools Releases" at "http://scala-tools.org/repo-releases",
+ "Sonatype Nexus Releases" at "https://oss.sonatype.org/content/repositories/releases",
+ "Sonatype Legacy Releases" at "https://oss.sonatype.org/content/repositories/releases",
+ "Sonatype staging" at "https://oss.sonatype.org/content/repositories/staging",
+ "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
+)
+
+libraryDependencies ++= Seq(
+ "com.typesafe.akka" % "akka-actor" % "2.0" withSources(),
+ "com.github.scala-incubator.io" % "scala-io-core_2.9.1" % "0.3.0" withSources(),
+ "com.github.scala-incubator.io" % "scala-io-file_2.9.1" % "0.3.0" withSources(),
+ "org.apache.httpcomponents" % "httpclient" % "4.1.2" withSources(),
+ "org.scala-tools" % "scala-stm_2.9.1" % "0.5" withSources(),
+ "org.scala-tools.time" % "time_2.9.1" % "0.5" ,
+ "org.scala-lang" % "scala-swing" % "2.9.1-1" withSources(),
+ "org.jfree" % "jfreechart" % "1.0.14" withSources()
+)
+
+seq(assemblySettings: _*)
+
+
+logLevel := Level.Error
+
+// Only show warnings and errors on the screen for compilations.
+// This applies to both test:compile and compile and is Info by default
+logLevel in compile := Level.Warn
+
View
8 project/plugins.sbt
@@ -1,4 +1,4 @@
-addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
-
-resolvers += Resolver.url("sbt-plugin-releases",
- new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
+
+resolvers += Resolver.url("sbt-plugin-releases",
+ new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
View
239 src/main/scala/com/micronautics/akka/benchmark/Benchmark.scala
@@ -1,112 +1,129 @@
-package com.micronautics.akka.benchmark
-
-/* Copyright 1012 Micronautics Research Corporation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Subject to the additional condition that the attribution code in Gui.scala
- remains untouched and displays each time the program runs.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-
-import akka.util.Duration.Inf
-import akka.dispatch.{Await, ExecutionContext, Future}
-import java.util.concurrent.{ExecutorService, Executor}
-import scala.collection.immutable.Map
-import akka.actor.ActorSystem
-
-/**
- * Does the heavy lifting for ExecutorBenchmark
- * @author Mike Slinn
- */
-class Benchmark (val ecNameMap: Map[Object, String],
- var load: () => Any,
- var showResult: Boolean
- ) {
- val NumInterations = 1000
- implicit var dispatcher: ExecutionContext = null
-
- /** Swing view */
- def showGui {
- val gui = new Gui(this)
- gui.startup(null)
- }
-
- def stop() { /* not implemented */ }
-
- def run() {
- println()
- ecNameMap.keys.foreach {
- e: Any =>
- if (e.isInstanceOf[ActorSystem]) {
- dispatcher = e.asInstanceOf[ActorSystem].dispatcher
- doit(ecNameMap.get(e.asInstanceOf[AnyRef]).get)
- e.asInstanceOf[ActorSystem].shutdown()
- } else {
- dispatcher = ExecutionContext.fromExecutor(e.asInstanceOf[Executor])
- doit(ecNameMap.get(e.asInstanceOf[AnyRef]).get)
- e.asInstanceOf[ExecutorService].shutdown()
- }
- }
- }
-
- def doit(executorName: String) {
- println("Warming up hotspot to test " + executorName)
- parallelTest
- Await.ready(futureTest, Inf)
- println("\nRunning tests on " + executorName)
- parallelTest
- Await.ready(futureTest, Inf)
- println("\n---------------------------------------------------\n")
- }
-
- def futureTest = {
- val t0 = System.nanoTime()
- val futures = time {
- for (i <- 1 to NumInterations) yield Future { load() }
- }("Futures creation time")
-
- Future sequence futures andThen {
- case f =>
- val t1 = System.nanoTime()
- println("Total time for Akka future version: " + (t1 - t0) / 1000000 + "ms")
- f match {
- case Right(result) =>
- if (showResult)
- println("Result using Akka future version: " + result)
- case Left(exception) =>
- println(exception.getMessage)
- }
- }
- }
-
- def parallelTest {
- val parallelResult = time {
- (1 to NumInterations).par.map { x => load() }
- }("Parallel collection elapsed time")
- if (showResult)
- println("Result using Scala parallel collections: " + parallelResult)
- }
-
- def time[R](block: => R)(msg: String="Elapsed time"): R = {
- val t0 = System.nanoTime()
- val result = block
- val t1 = System.nanoTime()
- println(msg + ": "+ (t1 - t0)/1000000 + "ms")
- result
- }
-}
-
-object Benchmark {
- def apply(ecNameMap: Map[Object, String])(load: () => Any)(showResult: Boolean=false) = {
- new Benchmark(ecNameMap: Map[Object, String], load, showResult)
- }
+package com.micronautics.akka.benchmark
+
+/* Copyright 1012 Micronautics Research Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Subject to the additional condition that the attribution code in Gui.scala
+ remains untouched and displays each time the program runs.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+import akka.util.Duration.Inf
+import akka.dispatch.{Await, ExecutionContext, Future}
+import java.util.concurrent.{ExecutorService, Executor}
+import scala.collection.immutable.Map
+import akka.actor.ActorSystem
+import Model.ecNameMap
+import com.micronautics.akka.DefaultLoad
+import akka.util.Duration
+
+/**
+ * Does the heavy lifting for ExecutorBenchmark
+ * @author Mike Slinn
+ */
+class Benchmark (var load: () => Any,
+ var showResult: Boolean
+ ) {
+ var consoleOutput: Boolean = true
+ val NumInterations: Int = 1000
+ implicit var dispatcher: ExecutionContext = null
+
+
+ /** Swing view */
+ def showGui {
+ val gui = new Gui(this)
+ gui.startup(null)
+ }
+
+ def stop() { /* not implemented */ }
+
+ def run() {
+ println()
+ ecNameMap.keys.foreach {
+ e: Any =>
+ if (e.isInstanceOf[ActorSystem]) {
+ dispatcher = e.asInstanceOf[ActorSystem].dispatcher
+ doit(ecNameMap.get(e.asInstanceOf[AnyRef]).get)
+ e.asInstanceOf[ActorSystem].shutdown()
+ } else {
+ dispatcher = ExecutionContext.fromExecutor(e.asInstanceOf[Executor])
+ doit(ecNameMap.get(e.asInstanceOf[AnyRef]).get)
+ e.asInstanceOf[ExecutorService].shutdown()
+ }
+ }
+ }
+
+ def doit(executorName: String) {
+ if (consoleOutput)
+ println("Warming up hotspot to test " + executorName)
+ parallelTest
+ futureTest
+// Await.ready(futureTest, Inf)
+ if (consoleOutput)
+ println("\nRunning tests on " + executorName)
+ parallelTest
+ futureTest
+// Await.ready(futureTest, Inf)
+ if (consoleOutput)
+ println("\n---------------------------------------------------\n")
+ }
+
+ def futureTest: Seq[Any] = {
+ val t0 = System.nanoTime()
+ val trFuture = time {
+ for (i <- 1 to NumInterations) yield Future { load() }
+ }("Futures creation time").asInstanceOf[TimedResult[Seq[Future[Any]]]]
+
+ val f2 = Future sequence trFuture.result andThen {
+ case f =>
+ val t1 = System.nanoTime()
+ println("Total time for Akka future version: " + (t1 - t0) / 1000000 + "ms")
+ f match {
+ case Right(timedResult: TimedResult[Any]) =>
+ if (showResult)
+ println("Result using Akka future version: " + timedResult.result)
+ timedResult
+ case Left(exception) =>
+ println(exception.getMessage)
+ TimedResult(0, null)
+ case _ =>
+ TimedResult(0, null)
+ }
+ }
+ val x = Await.result(f2, Duration.Inf)
+ x.asInstanceOf[Seq[Any]]
+ }
+
+ def parallelTest: TimedResult[Any] = {
+ val timedResult = time {
+ (1 to NumInterations).par.map { x => load() }
+ }("Parallel collection elapsed time")
+ if (showResult)
+ println("Result using Scala parallel collections: " + timedResult.result)
+ timedResult
+ }
+
+ def time(block: => Any)(msg: String="Elapsed time"): TimedResult[Any] = {
+ val t0 = System.nanoTime()
+ val result: Any = block
+ val t1 = System.nanoTime()
+ if (consoleOutput)
+ println(msg + ": "+ (t1 - t0)/1000000 + "ms")
+ TimedResult((t1 - t0)/1000000, result)
+ }
+}
+
+object Benchmark {
+ def apply(load: () => Any = DefaultLoad.run, showResult: Boolean=false) = {
+ new Benchmark(load, showResult)
+ }
}
View
74 ...autics/akka/benchmark/ExpensiveCalc.scala → ...onautics/akka/benchmark/DefaultLoad.scala
@@ -1,36 +1,38 @@
-package com.micronautics.akka
-
-/* Copyright 1012 Micronautics Research Corporation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Subject to the additional condition that the attribution code in Gui.scala
- remains untouched and displays each time the program runs.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-
-/** Default load for ExecutorBenchmark
- * @author Mike Slinn
- * @author calculatePiFor() provided by Typesafe
- */
-
-class ExpensiveCalc {}
-
-object ExpensiveCalc {
- def run(): Any = { calculatePiFor(0, 1000000) }
-
- def calculatePiFor(start: Int, nrOfElements: Int): Double = {
- var acc = 0.0
- for (i <- start until (start + nrOfElements))
- acc += 4.0 * (1 - (i % 2) * 2) / (2 * i + 1)
- acc
- }
-}
+package com.micronautics.akka
+
+/* Copyright 1012 Micronautics Research Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Subject to the additional condition that the attribution code in Gui.scala
+ remains untouched and displays each time the program runs.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+/** Default load for ExecutorBenchmark
+ * @author Mike Slinn
+ * @author calculatePiFor() provided by Typesafe
+ */
+
+class DefaultLoad {}
+
+object DefaultLoad {
+ var intensity = 1000000
+
+ def run(): Any = { calculatePiFor(0, intensity) }
+
+ def calculatePiFor(start: Int, nrOfElements: Int): Double = {
+ var acc = 0.0
+ for (i <- start until (start + nrOfElements))
+ acc += 4.0 * (1 - (i % 2) * 2) / (2 * i + 1)
+ acc
+ }
+}
View
170 src/main/scala/com/micronautics/akka/benchmark/ExecutorBenchmark.scala
@@ -1,85 +1,85 @@
-package com.micronautics.akka.benchmark
-
-/* Copyright 1012 Micronautics Research Corporation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Subject to the additional condition that the attribution code in Gui.scala
- remains untouched and displays each time the program runs.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-
-import akka.jsr166y.ForkJoinPool
-import java.util.concurrent.Executors
-import akka.actor.ActorSystem
-import com.typesafe.config.ConfigFactory
-import collection.parallel.ForkJoinTasks
-import collection.immutable.ListMap
-import com.micronautics.akka.ExpensiveCalc
-
-/** Sample setup for Benchmark
- * @author Mike Slinn */
-object ExecutorBenchmark extends App {
- val nProcessors = Runtime.getRuntime.availableProcessors
- val esFJP = new ForkJoinPool()
- val esFTPn = Executors.newFixedThreadPool(nProcessors)
- val esFTP1 = Executors.newFixedThreadPool(1)
- val esCTP = Executors.newCachedThreadPool()
- val esSTE = Executors.newSingleThreadExecutor()
-
- private val configString1: String = """akka {
- logConfigOnStart=off
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = %d
- parallelism-factor = 3.0
- parallelism-max = %d
- }
- }""".format(nProcessors, nProcessors)
- private val system1 = ActorSystem.apply("default1", ConfigFactory.parseString(configString1))
-
- private val configString2: String = """akka {
- logConfigOnStart=off
- executor = "thread-pool-executor"
- fork-join-executor {
- core-pool-size-min = %d
- parallelism-factor = 3.0
- core-pool-size-max = %d
- }
- }""".format(nProcessors, nProcessors)
- private val system2 = ActorSystem.apply("default2", ConfigFactory.parseString(configString2))
-
- private val configString3: String = """akka {
- logConfigOnStart=off
- executor = "thread-pool-executor"
- fork-join-executor {
- core-pool-size-min = %d
- parallelism-factor = 1.0
- core-pool-size-max = %d
- }
- }""".format(nProcessors, nProcessors)
- private val system3 = ActorSystem.apply("default2", ConfigFactory.parseString(configString3))
-
- val ecNameMap = ListMap(
- system1 -> "Akka ActorSystem w/ fork-join-executor",
- system2 -> "Akka ActorSystem w/ thread-pool-executor & parallelism-factor=3",
- system3 -> "Akka ActorSystem w/ thread-pool-executor & parallelism-factor=1",
- esFJP -> "Updated ForkJoinPool",
- esFTP1 -> "FixedThreadPool w/ nProcessors=1",
- esFTPn -> "FixedThreadPool w/ nProcessors=%d".format(nProcessors),
- esCTP -> "CachedThreadPool",
- esSTE -> "SingleThreadExecutor"
- )
-
- ForkJoinTasks.defaultForkJoinPool.setParallelism(nProcessors)
-
- Benchmark(ecNameMap)(ExpensiveCalc.run)(false) showGui
-}
+package com.micronautics.akka.benchmark
+
+/* Copyright 1012 Micronautics Research Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Subject to the additional condition that the attribution code in Gui.scala
+ remains untouched and displays each time the program runs.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+import akka.jsr166y.ForkJoinPool
+import java.util.concurrent.Executors
+import akka.actor.ActorSystem
+import com.typesafe.config.ConfigFactory
+import collection.parallel.ForkJoinTasks
+import collection.immutable.ListMap
+import com.micronautics.akka.DefaultLoad
+
+/** Sample setup for Benchmark
+ * @author Mike Slinn */
+object ExecutorBenchmark extends App {
+ val nProcessors = Runtime.getRuntime.availableProcessors
+ val esFJP = new ForkJoinPool()
+ val esFTPn = Executors.newFixedThreadPool(nProcessors)
+ val esFTP1 = Executors.newFixedThreadPool(1)
+ val esCTP = Executors.newCachedThreadPool()
+ val esSTE = Executors.newSingleThreadExecutor()
+
+ private val configString1: String = """akka {
+ logConfigOnStart=off
+ executor = "fork-join-executor"
+ fork-join-executor {
+ parallelism-min = %d
+ parallelism-factor = 3.0
+ parallelism-max = %d
+ }
+ }""".format(nProcessors, nProcessors)
+ private val system1 = ActorSystem.apply("default1", ConfigFactory.parseString(configString1))
+
+ private val configString2: String = """akka {
+ logConfigOnStart=off
+ executor = "thread-pool-executor"
+ fork-join-executor {
+ core-pool-size-min = %d
+ parallelism-factor = 3.0
+ core-pool-size-max = %d
+ }
+ }""".format(nProcessors, nProcessors)
+ private val system2 = ActorSystem.apply("default2", ConfigFactory.parseString(configString2))
+
+ private val configString3: String = """akka {
+ logConfigOnStart=off
+ executor = "thread-pool-executor"
+ fork-join-executor {
+ core-pool-size-min = %d
+ parallelism-factor = 1.0
+ core-pool-size-max = %d
+ }
+ }""".format(nProcessors, nProcessors)
+ private val system3 = ActorSystem.apply("default2", ConfigFactory.parseString(configString3))
+
+ Model.ecNameMap ++= ListMap(
+ system1 -> "Akka ActorSystem w/ fork-join-executor",
+ system2 -> "Akka ActorSystem w/ thread-pool-executor & parallelism-factor=3",
+ system3 -> "Akka ActorSystem w/ thread-pool-executor & parallelism-factor=1",
+ esFJP -> "Updated ForkJoinPool",
+ esFTP1 -> "FixedThreadPool w/ nProcessors=1",
+ esFTPn -> "FixedThreadPool w/ nProcessors=%d".format(nProcessors),
+ esCTP -> "CachedThreadPool",
+ esSTE -> "SingleThreadExecutor"
+ )
+
+ ForkJoinTasks.defaultForkJoinPool.setParallelism(nProcessors)
+
+ Benchmark() showGui
+}
View
301 src/main/scala/com/micronautics/akka/benchmark/Gui.scala
@@ -1,149 +1,152 @@
-package com.micronautics.akka.benchmark
-
-/* Copyright 1012 Micronautics Research Corporation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Subject to the additional condition that the attribution code in Gui.scala
- remains untouched and displays each time the program runs.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-
-import com.micronautics.util.PersistableApp
-import org.joda.time.DateTime
-import java.io.File
-import java.util.Properties
-import swing._
-import event._
-import org.jfree.data.category.DefaultCategoryDataset
-import org.jfree.chart.plot.PlotOrientation
-import org.jfree.chart.{ChartPanel, ChartFactory}
-import javax.swing.{JPanel, WindowConstants}
-import org.jfree.ui.RectangleInsets
-import org.jfree.chart.renderer.category.BarRenderer
-import java.net.URI
-import java.awt.{Paint, Cursor, Desktop}
-/**
- * @author Mike Slinn */
-class Gui (benchmark: Benchmark) extends SimpleSwingApplication with PersistableApp {
- var running: Boolean = false
- private val navigator = new Navigator
- private val attribution = new Label() { // The license requires this block to remain untouched
- text = "Copyright Micronautics Research Corporation. All rights reserved."
- cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
- listenTo(mouse.clicks, mouse.moves)
- reactions += {
- case MousePressed(src, point, i1, i2, b) =>
- Desktop.getDesktop.browse(new URI("http://micronauticsresearch.com"))
- }
- }
-
- attribution.peer.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT)
-
- def top = new MainFrame {
- var lastRun: DateTime = new DateTime(0)
-
- peer.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)
- title = "Executor Benchmark v0.1"
- size = new Dimension(575, 900)
-
- contents = new BoxPanel(Orientation.Vertical) {
- val graphs = graphSets
- peer.setBackground(graphs.getBackground)
-
- contents += navigator
- peer.add(graphs)
- contents += new Label(" ")
- contents += new Label(" ")
- contents += attribution
- border = Swing.EmptyBorder(30, 30, 10, 30)
- }
-
- reactions += {
- case WindowOpened(_) =>
- loadProperties
- visible = true
-
- case WindowClosing(_) =>
- saveProperties(locationOnScreen, size)
- sys.exit(0)
- }
-
- def graphSets: JPanel = {
- val dataset = new DefaultCategoryDataset()
- var i = 100
- benchmark.ecNameMap.keys.foreach { k =>
- dataset.addValue(1234, benchmark.ecNameMap.get(k).get, "Warm-up")
- dataset.addValue(1111, benchmark.ecNameMap.get(k).get, "Timed")
- i = i + 100
- }
-
- val barChart = ChartFactory.createBarChart("", "", "milliseconds", dataset, PlotOrientation.HORIZONTAL, true, true, false)
- barChart.getTitle.setFont(new Font("SanSerif", 0, 16))
- barChart.setPadding(new RectangleInsets(20, 0, 0, 0))
- barChart.setBackgroundPaint(new Color(0.8f, 0.8f, 0.8f))
- barChart.getLegend.setMargin(20, 0, 0, 0)
-
- val renderer = barChart.getCategoryPlot().getRenderer().asInstanceOf[BarRenderer]
- renderer.setDrawBarOutline(false)
- //renderer.setSeriesPaint(0, new Color(14, 107, 14));
- //renderer.setSeriesPaint(1, new Color(42, 94, 130));
- renderer.setMaximumBarWidth(1.0/(benchmark.ecNameMap.keys.size+1))
-
- val chartPanel = new ChartPanel(barChart, false) {
- setPreferredSize(new Dimension(500, 50*benchmark.ecNameMap.keys.size))
- setBackground(barChart.getBackgroundPaint.asInstanceOf[Color])
- }
- val panel = new JPanel
- panel.setBackground(chartPanel.getBackground)
- panel.add(chartPanel)
- panel
- }
-
- private def loadProperties {
- val props = readProperties(new File("executorBenchmark.properties"))
- location = new Point(props.getOrElse("x", "0").toInt, props.getOrElse("y", "0").toInt)
- size = new Dimension(props.getOrElse("width", "575").toInt, props.getOrElse("height", "900").toInt)
- lastRun = new DateTime(props.getOrElse("lastRun", "0"))
- }
-
- private def saveProperties(location: Point, size: Dimension) {
- val props = new Properties
- props.setProperty("x", location.getX.asInstanceOf[Int].toString)
- props.setProperty("y", location.getY.asInstanceOf[Int].toString)
- props.setProperty("width", size.getWidth.asInstanceOf[Int].toString)
- props.setProperty("height", size.getHeight.asInstanceOf[Int].toString)
- props.setProperty("lastRun", new DateTime().toString)
- writeProperties(new File("executorBenchmark.properties"), props)
- }
- }
-
- private class Navigator extends BoxPanel(Orientation.Horizontal) {
- val navItemHeight:Int = 20
- val buttonRunStop = new Button("Run")
- buttonRunStop.size = new Dimension(navItemHeight, navItemHeight)
-
- contents += buttonRunStop
- listenTo(buttonRunStop)
- reactions += {
- case ButtonClicked(button) =>
- if (button==buttonRunStop) {
- if (running) {
- benchmark.stop()
- button.text = "Run"
- } else {
- benchmark.run()
- button.text = "Stop"
- }
- }
- }
- }
-}
+package com.micronautics.akka.benchmark
+
+/* Copyright 1012 Micronautics Research Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Subject to the additional condition that the attribution code in Gui.scala
+ remains untouched and displays each time the program runs.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+import com.micronautics.util.PersistableApp
+import org.joda.time.DateTime
+import java.io.File
+import java.util.Properties
+import swing._
+import event._
+import org.jfree.data.category.DefaultCategoryDataset
+import org.jfree.chart.plot.PlotOrientation
+import org.jfree.chart.{ChartPanel, ChartFactory}
+import javax.swing.{JPanel, WindowConstants}
+import org.jfree.chart.renderer.category.BarRenderer
+import java.net.URI
+import java.awt.{Paint, Cursor, Desktop}
+import Model.ecNameMap
+import org.jfree.ui.{RectangleAnchor, HorizontalAlignment, RectangleEdge, RectangleInsets}
+
+/**
+ * @author Mike Slinn */
+class Gui (benchmark: Benchmark) extends SimpleSwingApplication with PersistableApp {
+ var running: Boolean = false
+ private val navigator = new Navigator
+ private val attribution = new Label() { // The license requires this block to remain untouched
+ text = "Copyright Micronautics Research Corporation. All rights reserved."
+ cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
+ listenTo(mouse.clicks, mouse.moves)
+ reactions += {
+ case MousePressed(src, point, i1, i2, b) =>
+ Desktop.getDesktop.browse(new URI("http://micronauticsresearch.com"))
+ }
+ }
+
+ attribution.peer.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT)
+
+ def top = new MainFrame {
+ var lastRun: DateTime = new DateTime(0)
+
+ peer.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)
+ title = "Executor Benchmark v0.1"
+ size = new Dimension(575, 900)
+
+ contents = new BoxPanel(Orientation.Vertical) {
+ val graphs = graphSets
+ peer.setBackground(graphs.getBackground)
+
+ contents += navigator
+ peer.add(graphs)
+ contents += new Label(" ")
+ contents += new Label(" ")
+ contents += attribution
+ border = Swing.EmptyBorder(30, 30, 10, 30)
+ }
+
+ reactions += {
+ case WindowOpened(_) =>
+ loadProperties
+ visible = true
+
+ case WindowClosing(_) =>
+ saveProperties(locationOnScreen, size)
+ sys.exit(0)
+ }
+
+ def graphSets: JPanel = {
+ val dataset = new DefaultCategoryDataset()
+ var i = 100
+ ecNameMap.keys.foreach { k =>
+ dataset.addValue(1234, ecNameMap.get(k).get, "Warm-up")
+ dataset.addValue(1111, ecNameMap.get(k).get, "Timed")
+ i = i + 100
+ }
+
+ val barChart = ChartFactory.createBarChart("", "", "milliseconds", dataset, PlotOrientation.HORIZONTAL, true, true, false)
+ barChart.getTitle.setFont(new Font("SanSerif", 0, 16))
+ barChart.setPadding(new RectangleInsets(20, 0, 0, 0))
+ barChart.setBackgroundPaint(new Color(0.8f, 0.8f, 0.8f))
+ barChart.getLegend.setMargin(20, 0, 0, 0)
+ barChart.setAntiAlias(true)
+
+ val renderer = barChart.getCategoryPlot().getRenderer().asInstanceOf[BarRenderer]
+ renderer.setDrawBarOutline(false)
+ //renderer.setSeriesPaint(0, new Color(14, 107, 14));
+ //renderer.setSeriesPaint(1, new Color(42, 94, 130));
+ renderer.setMaximumBarWidth(1.0/(ecNameMap.keys.size+1))
+
+ val chartPanel = new ChartPanel(barChart, false) {
+ setPreferredSize(new Dimension(500, 50 * ecNameMap.keys.size))
+ setBackground(barChart.getBackgroundPaint.asInstanceOf[Color])
+ }
+ val panel = new JPanel
+ panel.setBackground(chartPanel.getBackground)
+ panel.add(chartPanel)
+ panel
+ }
+
+ private def loadProperties {
+ val props = readProperties(new File("executorBenchmark.properties"))
+ location = new Point(props.getOrElse("x", "0").toInt, props.getOrElse("y", "0").toInt)
+ size = new Dimension(props.getOrElse("width", "575").toInt, props.getOrElse("height", "900").toInt)
+ lastRun = new DateTime(props.getOrElse("lastRun", "0"))
+ }
+
+ private def saveProperties(location: Point, size: Dimension) {
+ val props = new Properties
+ props.setProperty("x", location.getX.asInstanceOf[Int].toString)
+ props.setProperty("y", location.getY.asInstanceOf[Int].toString)
+ props.setProperty("width", size.getWidth.asInstanceOf[Int].toString)
+ props.setProperty("height", size.getHeight.asInstanceOf[Int].toString)
+ props.setProperty("lastRun", new DateTime().toString)
+ writeProperties(new File("executorBenchmark.properties"), props)
+ }
+ }
+
+ private class Navigator extends BoxPanel(Orientation.Horizontal) {
+ val navItemHeight:Int = 20
+ val buttonRunStop = new Button("Run")
+ buttonRunStop.size = new Dimension(navItemHeight, navItemHeight)
+
+ contents += buttonRunStop
+ listenTo(buttonRunStop)
+ reactions += {
+ case ButtonClicked(button) =>
+ if (button==buttonRunStop) {
+ if (running) {
+ benchmark.stop()
+ button.text = "Run"
+ } else {
+ benchmark.run()
+ button.text = "Stop"
+ }
+ }
+ }
+ }
+}
View
29 src/main/scala/com/micronautics/akka/benchmark/Model.scala
@@ -0,0 +1,29 @@
+package com.micronautics.akka.benchmark
+
+import collection.mutable.ListMap
+
+/* Copyright 1012 Micronautics Research Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Subject to the additional condition that the attribution code in Gui.scala
+ remains untouched and displays each time the program runs.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+/**
+ * @author Mike Slinn */
+
+case class TimedResult[+T](millis: Long, result: T)
+
+object Model {
+ val ecNameMap = new ListMap[Object, String]
+}
View
100 src/main/scala/com/micronautics/util/PersistableApp.scala
@@ -1,50 +1,50 @@
-package com.micronautics.util
-
-/* Copyright 1012 Micronautics Research Corporation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Subject to the additional condition that the attribution code in Gui.scala
- remains untouched and displays each time the program runs.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-
-import java.util.Properties
-import java.io.{FileOutputStream, OutputStream, FileInputStream, File}
-import scala.collection.JavaConversions._
-
-/**
- * Provides ability for a Swing app to save and restore to a properties file.
- * Methods are protected so unit tests can be written, but not accessed outside this package.
- * @author Mike Slinn
- */
-trait PersistableApp {
- self =>
- protected def readProperties(file: File): scala.collection.mutable.Map[String, String] = {
- val props = new Properties
- val in = new FileInputStream(file)
- try {
- props.load(in)
- } finally {
- in.close
- }
- props
- }
-
- protected def writeProperties(file: File, props: Properties) = {
- val out: OutputStream = new FileOutputStream(file)
- try {
- props.store(out, "")
- } finally {
- out.close
- }
- }
-}
+package com.micronautics.util
+
+/* Copyright 1012 Micronautics Research Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Subject to the additional condition that the attribution code in Gui.scala
+ remains untouched and displays each time the program runs.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+import java.util.Properties
+import java.io.{FileOutputStream, OutputStream, FileInputStream, File}
+import scala.collection.JavaConversions._
+
+/**
+ * Provides ability for a Swing app to save and restore to a properties file.
+ * Methods are protected so unit tests can be written, but not accessed outside this package.
+ * @author Mike Slinn
+ */
+trait PersistableApp {
+ self =>
+ protected def readProperties(file: File): scala.collection.mutable.Map[String, String] = {
+ val props = new Properties
+ val in = new FileInputStream(file)
+ try {
+ props.load(in)
+ } finally {
+ in.close
+ }
+ props
+ }
+
+ protected def writeProperties(file: File, props: Properties) = {
+ val out: OutputStream = new FileOutputStream(file)
+ try {
+ props.store(out, "")
+ } finally {
+ out.close
+ }
+ }
+}

0 comments on commit 5b473a8

Please sign in to comment.