-
-
Save gabizou/33f616c08bde5ab97e56 to your computer and use it in GitHub Desktop.
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
For the original incomming damage of 10, we got: 54.405 | |
And it took 102021 milliseconds. | |
For the new incoming damage of 10, we got: 54.405 | |
And it took 3052727 milliseconds. | |
For the new parallel incoming damage of 10, we got: 52.4 | |
And it took 4592186 milliseconds. |
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
package com.gabizou; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.function.Function; | |
/** | |
* Derp. | |
*/ | |
public class StreamsTest { | |
private static final List<Function<? super Double, Double>> functions = new ArrayList<>(); | |
/** | |
* Derp. | |
* | |
* @param args derpington | |
*/ | |
public static void main(final String[] args) { | |
functions.add(aDouble -> aDouble * 0.5); | |
functions.add(aDouble -> aDouble + (-2.1)); | |
functions.add(aDouble -> aDouble * 0.95); | |
final long oldStart = System.nanoTime(); | |
double damage = 10; | |
for (Function<? super Double, Double> function : functions) { | |
damage += function.apply(damage); | |
} | |
final double oldDamage = damage; | |
final long oldEnd = System.nanoTime(); | |
final long oldDif = oldEnd - oldStart; | |
damage = 10; | |
final long newStart = System.nanoTime(); | |
final double newDamage = functions.stream().reduce(damage, (d, f) -> d + f.apply(d), | |
(a, b) -> a + b); | |
final long newEnd = System.nanoTime(); | |
final long newDif = newEnd - newStart; | |
final long parStart = System.nanoTime(); | |
final double parDamage = functions.parallelStream().reduce(damage, (d, f) -> d + f.apply(d), | |
(a, b) -> a + b); | |
final long parEnd = System.nanoTime(); | |
final long parDif = parEnd - parStart; | |
System.out.println("For the original incomming damage of 10, we got: " + oldDamage); | |
System.out.println("And it took " + oldDif + " milliseconds."); | |
System.out.println("For the new incoming damage of 10, we got: " + newDamage); | |
System.out.println("And it took " + newDif + " milliseconds."); | |
System.out.println("For the new parallel incoming damage of 10, we got: " + parDamage); | |
System.out.println("And it took " + parDif + " milliseconds."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment