Skip to content

Instantly share code, notes, and snippets.

szeiger@Stefans-MBP ~/code/dotty (master *=)
$ git clean -df
Removing dist-bootstrapped/
Removing dotty-bootstrapped/
Removing dotty-optimised/
Removing project/project/project/
Removing scala-compiler/
Removing scala-library/
Removing scala-reflect/
Removing scalap/
[info] Benchmark (size) (stringsOnly) Mode Cnt Score Error Units
[info] HashMapBenchmark2.fill 0 false avgt 20 19.403 ± 0.136 ns/op
[info] HashMapBenchmark2.fill 1 false avgt 20 32.029 ± 0.360 ns/op
[info] HashMapBenchmark2.fill 10 false avgt 20 281.508 ± 3.443 ns/op
[info] HashMapBenchmark2.fill 100 false avgt 20 6840.049 ± 119.193 ns/op
[info] HashMapBenchmark2.fill 1000 false avgt 20 84998.278 ± 2454.868 ns/op
[info] HashMapBenchmark2.fill 10000 false avgt 20 924593.503 ± 13564.179 ns/op
[info] HashMapBenchmark2.getExisting 0 false avgt 20 0.631 ± 0.009 ns/op
[info] HashMapBenchmark2.getExisting 1 false avgt 20 13.986 ± 0.299 ns/op
[info] HashMapBenchmark2.getExisting 10 false avgt
import scala.collection.immutable.HashMap$;
import scala.collection.immutable.HashMap;
import scala.collection.immutable.Map;
import scala.collection.mutable.Builder;
import scala.Tuple2;
public class JavaCallingScalaHashMap {
public static void main( String[] args ) {
Map<String, Integer> hashMap = HashMap$.MODULE$.empty();
@szeiger
szeiger / gist:d73a42b67a318244a7ef04ae7021e260
Created September 27, 2018 14:49
When you think 5 or 10 warmup iterations are sufficient...
[info] # Run progress: 91.67% complete, ETA 00:00:50
[info] # Fork: 2 of 2
[info] # Warmup Iteration 1: 94986.818 ns/op
[info] # Warmup Iteration 2: 90830.986 ns/op
[info] # Warmup Iteration 3: 90552.242 ns/op
[info] # Warmup Iteration 4: 93412.241 ns/op
[info] # Warmup Iteration 5: 90682.330 ns/op
[info] # Warmup Iteration 6: 92394.442 ns/op
[info] # Warmup Iteration 7: 95510.477 ns/op
[info] # Warmup Iteration 8: 92989.488 ns/op
@szeiger
szeiger / gist:81fed5b31a70415ed7e8a82182f2df94
Created March 19, 2018 17:11
git blame src/library/scala/collection/immutable/LongMap.scala
0394b8426ff src/library/scala/collection/immutable/LongMap.scala (Aleksandar Prokopec 2010-07-09 11:31:34 +0000 1) /* __ *\
0394b8426ff src/library/scala/collection/immutable/LongMap.scala (Aleksandar Prokopec 2010-07-09 11:31:34 +0000 2) ** ________ ___ / / ___ Scala API **
807dbe557a4 src/library/scala/collection/immutable/LongMap.scala (Heather Miller 2012-11-02 18:12:57 +0100 3) ** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
0394b8426ff src/library/scala/collection/immutable/LongMap.scala (Aleksandar Prokopec 2010-07-09 11:31:34 +0000 4) ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
0394b8426ff src/library/scala/collection/immutable/LongMap.scala (
use std::ops::Add;
struct Point<T, U> { x: T, y: U }
impl<T : Add<Output=T>> Point<T, T> {
fn f(self) -> T { self.x + self.y }
}
fn main() {
Point { x: 1, y: 2.0 }.f();
@szeiger
szeiger / gist:3a2e7e65b641bac9764a9c02de233ab9
Last active May 16, 2018 13:58
Kind-polymorphic Any and Nothing
scala> def f[C[_], E]: List[C[E]] = Nil
warning: there was one feature warning; re-run with -feature for details
f: [C[_], E]=> List[C[E]]
scala> f[List, Int]
res5: List[List[Int]] = List()
scala> f[Any, Int]
res6: List[Any] = List()
public scala.Tuple2<java.lang.Object, java.lang.Object> find(int[][], int);
Code:
0: iconst_0
1: istore_3
2: iload_3
3: aload_1
4: arraylength
5: if_icmpge 60
8: aload_1
9: iload_3
def find(a: Array[Array[Int]], v: Int): (Int, Int) = {
var i = 0
while(i < a.length) {
val aa = a(i)
var j = 0
while(j < aa.length) {
if(aa(j) == v) return (i, j)
j += 1
}
i += 1
def find(a: Array[Array[Int]], v: Int): (Int, Int) = {
var i = 0
while(i < a.length) {
val aa = a(i)
var j = 0
while(j < aa.length) {
if(aa(j) == v) return (i, j)
j += 1
}
i += 1