Created
January 22, 2016 18:22
-
-
Save netzwerg/7c5b51a87567fd95a14e to your computer and use it in GitHub Desktop.
Using RC2, zip variant is 10x slower (1500 ms vs. 150 ms)
This file contains 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 javaslang.collection.List; | |
import org.junit.Test; | |
import java.util.Iterator; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
public class ZipSpeedTest { | |
private static final java.util.List<String> JAVA_LIST = IntStream.range(0, 1_000_000).mapToObj(String::valueOf).collect(Collectors.toList()); | |
private static final java.lang.Iterable<String> JAVA_ITERABLE = JAVA_LIST::iterator; | |
private static final List<String> SLANG_LIST = List.range(0, 1_000_000).map(String::valueOf); | |
@Test | |
public void zip() { | |
long startTime = System.currentTimeMillis(); | |
SLANG_LIST.zip(JAVA_ITERABLE).map(t -> t._1 + t._2); | |
System.out.println("Variant 'zip': " + (System.currentTimeMillis() - startTime)); | |
} | |
@Test | |
public void next() { | |
long startTime = System.currentTimeMillis(); | |
Iterator<String> it = JAVA_ITERABLE.iterator(); | |
SLANG_LIST.map(e -> e + it.next()); | |
System.out.println("Variant 'next': " + (System.currentTimeMillis() - startTime)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment