Skip to content

Commit f26a0d7

Browse files
committed
Refactored test to compare lambdas
1 parent 1f4c551 commit f26a0d7

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

java/org/lambda/tests/EfficiencyTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
package org.lambda.tests;
22

3-
import java.text.MessageFormat;
4-
5-
import junit.framework.TestCase;
6-
73
import org.approvaltests.legacycode.Range;
4+
import org.lambda.functions.Function1;
85
import org.lambda.functions.implementations.F1;
96
import org.lambda.query.Query;
107

8+
import junit.framework.TestCase;
9+
1110
public class EfficiencyTest extends TestCase
1211
{
1312
public void testFastLambdas() throws Exception
1413
{
1514
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();
2415
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)
2717
{
2818
{
2919
ret(a == matching);
3020
}
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);
3233
long end = System.currentTimeMillis();
3334
long diff = end - start;
3435
return diff;

0 commit comments

Comments
 (0)