Skip to content

Instantly share code, notes, and snippets.

@danieldietrich
Last active September 20, 2017 19:01
Show Gist options
  • Save danieldietrich/13fd9080e605d7a092354b763f47c4fc to your computer and use it in GitHub Desktop.
Save danieldietrich/13fd9080e605d7a092354b763f47c4fc to your computer and use it in GitHub Desktop.
Who has the fastest machine? πŸ˜„

Challenge

Include the Maven / Gradle dependency io.vavr:vavr:0.9.1

and run the code below. Your fastest run counts.

(Note: this is not some kind of benchmarking, it is part of the 'challange' to use it as-is.)

Write the result at Twitter as a reply to: https://twitter.com/vavr_io/status/910550358635761665

import io.vavr.collection.Iterator;
import io.vavr.collection.Seq;
public class Test {
public static void main(String[] args) {
int size = 10;
Iterator<String> iter = Iterator.continually(() -> (char) (Math.random() * ((122 - 48) + 1) + 48))
.filter(i -> (i < 57 || i > 65) && (i < 90 || i > 97))
.sliding(size, size)
.map(Seq::mkString);
int count = 0;
final long time = System.nanoTime();
while (System.nanoTime() - time < 10_000_000_000L) {
iter.next();
count ++;
}
System.out.println((count / 10) + " per second");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment