Skip to content

Instantly share code, notes, and snippets.

Group
+----------+-------------+---------+---------+
| Language | Benchmark | Score | Error |
+----------+-------------+---------+---------+
| Java | Collections | 509,416 | 9,455 | <-- (2)
| Java | Streams | 583,236 | 27,646 | <-- (1)
| Scala | Collections | 419,362 | 30,810 | <-- (3)
| Scala | Streams | 117,557 | 7,985 |
| Scala | Views | 357,861 | 4,734 |
+----------+-------------+---------+---------+
Map then collect
+----------+-------------+-------------+-------------+
| Language | Benchmark | Score | Error |
+----------+-------------+-------------+-------------+
| Java | Collections | 1,156,656 | 18,053 | <-- (3)
| Java | Streams | 922,486 | 13,691 |
| Scala | Collections | 435,280 | 8,956 |
| Scala | Streams | 68,349,631 | 2,182,853 | <-- (2)
| Scala | Views | 141,833,408 | 1,110,245 | <-- (1)
+----------+-------------+-------------+-------------+
Map then reduce
+----------+-------------+------------+-------------+
| Language | Benchmark | Score | Error |
+----------+-------------+------------+-------------+
| Java | Collections | 10,989,113 | 319,941 | <-- (1)
| Java | Streams | 944,391 | 16,689 | <-- (2)
| Scala | Collections | 314,736 | 6,594 |
| Scala | Streams | 115,335 | 1,467 |
| Scala | Views | 476,832 | 9,358 | <-- (3)
+----------+-------------+------------+-------------+
Find first
+----------+-------------+------------+-----------+
| Language | Benchmark | Score | Error |
+----------+-------------+------------+-----------+
| Java | Collections | 80,444,836 | 1,358,358 | <-- (1)
| Java | Streams | 26,209,187 | 469,668 |
| Scala | Collections | 65,145,791 | 2,699,582 | <-- (3)
| Scala | Streams | 6,923,533 | 179,960 |
| Scala | Views | 58,082,123 | 1,004,918 | <-- (2)
+----------+-------------+------------+-----------+
Filter then sort then map then collect
+----------+-------------+---------+-------+
| Language | Benchmark | Score | Error |
+----------+-------------+---------+-------+
| Java | Collections | 13,615 | 255 |
| Java | Streams | 11,861 | 213 |
| Scala | Collections | 45,009 | 805 | <-- (3)
| Scala | Streams | 56,409 | 882 | <-- (2)
| Scala | Views | 139,639 | 2,875 | <-- (1)
+----------+-------------+---------+-------+
╔══════╦══════╦════════╗
║ Col1 ║ Col2 ║ NumCol ║
╠══════╬══════╬════════╣
║ MMM ║ MMM ║ MMM ║
║ 111 ║ 111 ║ 111 ║
║ AAA ║ AAA ║ AAA ║
╚══════╩══════╩════════╝
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
@BenchmarkMode({Mode.Throughput})
class Application extends Controller {
...
implicit val akkaSystem = akka.actor.ActorSystem()
val redis = RedisClient()
def index = Action { implicit request =>
Ok(views.html.pubsub())
class SubscribeActor(redis: RedisClient, out: ActorRef,
channels: Seq[String] = Nil, patterns: Seq[String] = Nil) extends RedisSubscriberActor(
new InetSocketAddress(redis.host, redis.port), channels, patterns,
onConnectStatus = connected => { println(s"connected: $connected") }) {
def onMessage(message: Message) {
out ! message.data.decodeString("UTF-8")
}
def onPMessage(pmessage: PMessage) {}
var socket = null
function subscribe(channel) {
var subscribeUrl = jsRoutes.controllers.Application.subscribe().webSocketURL() + "?channel=" + channel
console.log("Subscribed to: " + subscribeUrl)
socket = new WebSocket(subscribeUrl)
socket.onmessage = function(event) {
$("#messages" ).prepend("<div>" + event.data + "</div>")
}
socket.onclose = function(event) {
console.log(event)