This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sample benchmark: https://gist.github.com/voronaam/11273582 | |
Setup instruction: http://blog.vorona.ca/measuring-scala-performance-with-jmh.html | |
Regexp benchmark: | |
someString.split("[_,;,-]"); | |
vs | |
private static final Pattern PATTERN = Pattern.compile("[_,;,-]"); | |
PATTERN.split(someString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Test results: | |
Benchmark Mode Samples Mean Mean error Units | |
c.t.MyBenchmark.testString thrpt 200 391517.835 3311.834 ops/ms | |
c.t.MyBenchmark.testSymbol thrpt 200 36618.384 193.733 ops/ms | |
*/ | |
package com.test { | |
import org.openjdk.jmh.annotations.GenerateMicroBenchmark |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait XsnTypeMode extends PrimitiveTypeMode { | |
import com.codahale.jerkson.Json._ | |
import scala.collection.mutable.HashMap | |
import scala.language.implicitConversions | |
implicit val jsonTEF = new NonPrimitiveJdbcMapper[String,HashMap[String, Any],TString](stringTEF, this) { | |
def convertFromJdbc(v: String) = if(v == null) null else parse[HashMap[String, Any]](v) | |
def convertToJdbc(v: HashMap[String, Any]) = if(v == null) null else generate(v) | |
override def sample = new HashMap[String, Any]() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.{ Collection => JCollection } | |
import java.lang.{ Long => JLong } | |
import java.sql.Timestamp | |
import scala.collection.JavaConversions._ | |
import org.squeryl.Query | |
import com.vaadin.data._ | |
import scala.reflect.ClassTag | |
import org.squeryl.dsl.ast.OrderByArg | |
import org.squeryl.dsl.ast.ExpressionNode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A function to parse page set defintion, which supports [overlapping] ranges | |
def pageSet(definition: String) = { | |
def pageDefToSet(pageDef: String): Set[Int] = { | |
val rangeExtractor = """[^\d]*([\d]+).*-[^\d]*([\d])+[^\d]*""".r | |
val numberExtractor = """[^\d]*([\d]+)[^\d]*""".r | |
pageDef match { | |
case rangeExtractor(from, to) => (from.toInt to to.toInt).toSet | |
case numberExtractor(num) => Set(num.toInt) | |
case _ => Set() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.swing.{ Component, Swing, event } | |
import javax.swing.JComboBox | |
/** | |
* Very basic Mutable ComboBox for Scala. | |
* <p>Sample usage:<p> | |
* <pre> | |
* val box = new MutableComboBox[String] | |
* box.items = List("1", "11", "222") | |
* listenTo(box) |
NewerOlder