Skip to content

Commit

Permalink
Merge pull request #4 from mscharley/cross-build
Browse files Browse the repository at this point in the history
Cross build
  • Loading branch information
mscharley authored Mar 17, 2017
2 parents 7b335a3 + fb8e1e3 commit 3817659
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 29 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.3.2
11 changes: 7 additions & 4 deletions benchmark/src/main/scala/Benchmark.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import com.mscharley.random._
import org.scalameter._

// scalastyle:off regex
object Benchmark extends App {
val ITERATIONS = 10000
val BENCHES = 1000
val SMALL_BYTE_COUNT = 16
val LARGE_BYTE_COUNT = 4096

private val measurer = config(
Key.exec.benchRuns -> BENCHES
Expand All @@ -29,21 +32,21 @@ object Benchmark extends App {
val intImprovement = (1 - timeXoroInt.value / timeJavaInt.value) * 100

val timeJavaBytes = measurer measure { for (i <- 0 until ITERATIONS / 16) yield {
val b = Array.ofDim[Byte](16)
val b = Array.ofDim[Byte](SMALL_BYTE_COUNT)
scalaRand.nextBytes(b)
} }
val timeXoroBytes = measurer measure { for (i <- 0 until ITERATIONS / 16) yield {
val b = Array.ofDim[Byte](16)
val b = Array.ofDim[Byte](SMALL_BYTE_COUNT)
xoroRand.nextBytes(b)
} }
val bytesImprovement = (1 - timeXoroBytes.value / timeJavaBytes.value) * 100

val timeJavaBytesBig = measurer measure { for (i <- 0 until ITERATIONS / 4096) yield {
val b = Array.ofDim[Byte](4096)
val b = Array.ofDim[Byte](LARGE_BYTE_COUNT)
scalaRand.nextBytes(b)
} }
val timeXoroBytesBig = measurer measure { for (i <- 0 until ITERATIONS / 4096) yield {
val b = Array.ofDim[Byte](4096)
val b = Array.ofDim[Byte](LARGE_BYTE_COUNT)
xoroRand.nextBytes(b)
} }
val bytesBigImprovement = (1 - timeXoroBytesBig.value / timeJavaBytesBig.value) * 100
Expand Down
53 changes: 30 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
import sbtcrossproject.{CrossType, crossProject}

lazy val commonSettings = Seq(
scalaVersion := "2.11.8",
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-Xlint")
)

lazy val xoroshiro128 = (project in file(".")).
settings(commonSettings : _*).
settings(
organization := "com.mscharley",
name := "xoroshiro128",

libraryDependencies ++= Seq(
// Disambiguation.
"org.scala-lang" % "scala-reflect" % "2.11.8",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4",
"org.scala-lang.modules" %% "scala-xml" % "1.0.4",
lazy val testingSettings = Seq(
libraryDependencies ++= Seq(
// Testing libraries.
"org.scalatest" %%% "scalatest" % "3.0.1" % "test"
)
)

// Testing libraries.
"org.scalatest" %% "scalatest" % "3.0.0" % "test"
lazy val xoroshiro128 =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.settings(
commonSettings,
organization := "com.mscharley",
name := "xoroshiro128"
)
)
.jvmSettings(testingSettings)
.jsSettings(testingSettings)

lazy val xoroshiro128JVM = xoroshiro128.jvm
lazy val xoroshiro128JS = xoroshiro128.js
lazy val xoroshiro128Native = xoroshiro128.native

lazy val benchmark = (project in file("benchmark")).
settings(commonSettings : _*).
settings(
mainClass in Compile := Some("Benchmark"),
lazy val benchmark =
(project in file("benchmark"))
.settings(
commonSettings,
mainClass in Compile := Some("Benchmark"),

// Scalameter for speed testing.
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases",
libraryDependencies += "com.storm-enroute" %% "scalameter-core" % "0.7"
).dependsOn(xoroshiro128)
// Scalameter for speed testing.
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases",
libraryDependencies += "com.storm-enroute" %% "scalameter-core" % "0.7"
).dependsOn(xoroshiro128JVM)
23 changes: 22 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
machine:
java:
version: openjdk8
node:
version: 4.3.2
post:
- curl -s https://raw.githubusercontent.com/paulp/sbt-extras/master/sbt > ~/bin/sbt && chmod 0755 ~/bin/sbt

dependencies:
post:
pre:
- sudo apt-get update
- sudo apt-get install clang libgc-dev
- cat /dev/null | sbt update
override:
- cat /dev/null | sbt xoroshiro128JVM/test:compile
- cat /dev/null | sbt xoroshiro128JS/test:compile
- cat /dev/null | sbt xoroshiro128Native/compile
- cat /dev/null | sbt benchmark/test:compile
cache_directories:
- "~/.ivy2"
- "~/.m2"
- "~/.sbt"
- "~/.lib"

test:
pre:
- cat /dev/null | sbt scalastyle
override:
- cat /dev/null | sbt xoroshiro128JVM/test:test
- cat /dev/null | sbt xoroshiro128JS/test:test
post:
- cat /dev/null | sbt benchmark/run
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.11
sbt.version=0.13.13
8 changes: 8 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Cross-building dependencies.
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")
addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.1.0")
addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.1.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.1.0")

// Other assorted goodies.
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
117 changes: 117 additions & 0 deletions scalastyle-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="error" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.file.HeaderMatchesChecker" enabled="false">
<parameters>
<parameter name="header"><![CDATA[// Copyright (C) 2011-2012 the original author or authors.
// See the LICENCE.txt file distributed with this work for additional
// information regarding copyright ownership.
//
// 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
//
// 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.]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.FileLineLengthChecker" enabled="true">
<parameters>
<parameter name="maxLineLength"><![CDATA[160]]></parameter>
<parameter name="tabSize"><![CDATA[4]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true">
<parameters>
<parameter name="maxParameters"><![CDATA[8]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true">
<parameters>
<parameter name="maxTypes"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[10]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
<parameter name="doubleLineAllowed"><![CDATA[false]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true">
<parameters>
<parameter name="maxLength"><![CDATA[50]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true">
<parameters>
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
</scalastyle>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.mscharley.random._
import org.scalatest.FlatSpec

// scalastyle:off magic.number
class SplitMixSpec extends FlatSpec {
def checkSequence(seed : Long)(values : Long*) : Unit = {
val sm = splitmix64(seed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.mscharley.random._
import org.scalatest.FlatSpec

// scalastyle:off magic.number
class Xoroshiro128Spec extends FlatSpec {
def checkSequence(lo : Long, high : Long)(values : Long*) : Unit = {
val sm = xoroshiro128(lo, high)
Expand Down

0 comments on commit 3817659

Please sign in to comment.