|
1 | 1 | package org.lambda.tests; |
2 | 2 |
|
3 | | -import java.text.MessageFormat; |
4 | | - |
5 | | -import junit.framework.TestCase; |
6 | | - |
7 | 3 | import org.approvaltests.legacycode.Range; |
| 4 | +import org.lambda.functions.Function1; |
8 | 5 | import org.lambda.functions.implementations.F1; |
9 | 6 | import org.lambda.query.Query; |
10 | 7 |
|
| 8 | +import junit.framework.TestCase; |
| 9 | + |
11 | 10 | public class EfficiencyTest extends TestCase |
12 | 11 | { |
13 | 12 | public void testFastLambdas() throws Exception |
14 | 13 | { |
15 | 14 | int times = 1000000; |
16 | | - long diff = doManyTimes(times); |
17 | | - String time = MessageFormat.format("Time for {0} runs = {1}ms", times, diff); |
18 | | - System.out.println(time); |
19 | | - assertTrue(time, diff < 1400); |
20 | | - } |
21 | | - public long doManyTimes(int times) |
22 | | - { |
23 | | - long start = System.currentTimeMillis(); |
24 | 15 | final Integer matching = 18; |
25 | | - Integer[] r = Range.get(0, times); |
26 | | - Query.where(r, new F1<Integer, Boolean>(0, matching) |
| 16 | + System.out.println(getTimeStotistics("org.lamba", times, new F1<Integer, Boolean>(0, matching) |
27 | 17 | { |
28 | 18 | { |
29 | 19 | ret(a == matching); |
30 | 20 | } |
31 | | - }); |
| 21 | + })); |
| 22 | + System.out.println(getTimeStotistics("Lambda8", times, a -> a == matching)); |
| 23 | + } |
| 24 | + private String getTimeStotistics(String name, int times, Function1<Integer, Boolean> function) |
| 25 | + { |
| 26 | + return String.format("Time for %s %s runs = %sms", name, times, doManyTimesWithLambda(times, function)); |
| 27 | + } |
| 28 | + public long doManyTimesWithLambda(int times, Function1<Integer, Boolean> funct) |
| 29 | + { |
| 30 | + Integer[] r = Range.get(0, times); |
| 31 | + long start = System.currentTimeMillis(); |
| 32 | + Query.where(r, funct); |
32 | 33 | long end = System.currentTimeMillis(); |
33 | 34 | long diff = end - start; |
34 | 35 | return diff; |
|
0 commit comments