Skip to content

Instantly share code, notes, and snippets.

@netzwerg
Created January 22, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netzwerg/7c5b51a87567fd95a14e to your computer and use it in GitHub Desktop.
Save netzwerg/7c5b51a87567fd95a14e to your computer and use it in GitHub Desktop.
Using RC2, zip variant is 10x slower (1500 ms vs. 150 ms)
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