intobjs.add(i);
}
System.out.println();
System.out.println("--- Array and Collections ---");
System.out.println(benchmark(new F0() { // 9195
public void f() {
c1.toArray(new String[0]);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 9460
public void f() {
c1.toArray();
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 62650
public void f() {
c2.toArray();
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 181898
public void f() {
c2.toArray(new String[0]);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 84118
public void f() {
for (int i = 0; i < size; i++) {
strings[i] = c1.get(i).toLowerCase();
}
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 80942
public void f() {
for (int i = 0; i < size; i++) {
strings[i] = strings[i].toLowerCase();
}
}
}, 10) + "µs");
r.clear();
System.out.println(benchmark(new F0() { // 89496
public void f() {
for (String s : c1) {
r2.add(s.toLowerCase());
}
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 87272
public void f() {
int i = 0;
for (String s : c2) {
strings[i++] = s.toLowerCase();
}
}
}, 10) + "µs");
r.clear();
System.out.println(benchmark(new F0() { // 413666
public void f() {
for (String s : c2) {
r.add(s.toLowerCase());
}
}
}, 10) + "µs");
r.clear();
System.out.println(benchmark(new F0() { // 413666
public void f() {
for (String s : c2) {
r.add(s.toLowerCase());
}
}
}, 10) + "µs");
System.out.println();
System.out.println("--- Object Creation ---");
o1.clear();
System.out.println(benchmark(new F0() { // 159663 (wo caching),
// 356117 (w caching)
// 331769
// 14166 (optimized)
public void f() {
/*CoreClass<F0Impl> $2 = $(F0Impl.class);
for (int i = 0; i < size; i++)
o1.add($2.spawn());*/
}
}, 10) + "µs");
o1.clear();
System.out.println(benchmark(new F0() { // 2277
public void f() {
for (int i = 0; i < size; i++)
o1.add(new F0Impl());
}
}, 10) + "µs");
final AtomicInteger ress = new AtomicInteger();
System.out.println();
System.out.println("--- $() usage ---");
System.out.println(benchmark(new F0() { // 15117
public void f() {
int cnt = 0;
for (int i = 0; i < size; i++)
cnt += $(getOrNotObject()).compact().size();
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 3034
public void f() {
int cnt = 0;
for (int i = 0; i < size; i++) {
if (getOrNotObject() != null) cnt++;
}
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 227518
public void f() {
int cnt = 0;
for (int i = 0; i < size; i++)
cnt += $(getOrNotList()).size();
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 133315
public void f() {
int cnt = 0;
for (int i = 0; i < size; i++) {
List<Object> orNotList = getOrNotList();
cnt += orNotList.size();
}
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 3857
public void f() {
Object o = new Object();
int cnt = 0;
for (int i = 0; i < size; i++)
cnt += $(o).size();
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 30
public void f() {
Object o = new Object();
int cnt = 0;
for (int i = 0; i < size; i++) {
if (o != null) cnt += 1;
}
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 10409 // 839
public void f() {
int cnt = 0;
Object o = new Object();
for (int i = 0; i < size; i++) {
cnt += new Object().equals(o) ? 1 : 0;
}
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() { // 12071 // 2782
public void f() {
int cnt = 0;
Object o = new Object();
for (int i = 0; i < size; i++) {
cnt += $(o).equals(o) ? 1 : 0;
}
ress.addAndGet(cnt);
}
}, 10) + "µs");
System.out.println();
System.out.println("--- Iteration over Created ---");
System.out.println(benchmark(new F0() { // 278347
public void f() {
//$(F0Impl.class).spawned().each(F0.class).f();
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() { // 7450
for (Object f0 : o1) {
((F0Impl) f0).f();
}
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() { // 118806
$(o1).each(F0.class).f();
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() { // 26346
$(o1).map(new F1() {
public Object f(Object x) {
((F0) x).f();
return null;
}
});
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() { // 11012
$(o1);
}
}, 10) + "µs");
/*
* Removed, the ___map was the first version of map without the mapper, was ~10-20% faster but only
* when F1 was very lightweight. For heavyweight cases of F1 no significant difference was noticable.
long b11 = benchmark(new F0() {
public void f() {
$(strings).____map(new F1<String, String>() {
public String f(String x) {
return x.toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase();
//return x.toLowerCase();
}
});
}
}, 10) + "µs";
*/
long b1 = benchmark(new F0() {
public void f() {
$(strings).map(new F1<String, String>() {
public String f(String x) {
return x.toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase();
//return x.toLowerCase();
}
});
}
}, 10);
long b2 = benchmark(new F0() {
public void f() {
for (int i = 0; i < strings.length; i++) {
strings[i] = strings[i].toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase();
//strings[i] = strings[i].toLowerCase();
}
}
}, 10);
/*
long b3 = benchmark(new F0() {
public void f() {
$(ints).map(new F1Int2Int() {
public int f(int x) {
return (int) Math.sqrt(Math.tan(x * x));
}
});
}
}, 10);*/
long b4 = benchmark(new F0() {
public void f() {
for (int i = 0; i < ints.length; i++) {
int x = ints[i];
res[i] = (int) Math.sqrt(Math.tan(x * x));
}
}
}, 10);
long b6 = benchmark(new F0() {
public void f() {
for (int i = 0; i < longs.length; i++) {
resl[i] = longs[i] * longs[i];
}
}
}, 10);
System.out.println();
System.out.println("--- Parallelization Results ---");
System.out.println(b1);
System.out.println(b2);
//System.out.println(b3);
System.out.println(b4);
System.out.println(b6);
System.out.println();
System.out.println("--- Fancy Stuff ---");
System.out.println(benchmark(new F0() {
public void f() {
$(intobjs).fold(new F2ReduceObjects<Integer>() {
@Override
public Integer f(Integer stack, Integer next) {
return stack + next;
}
}).get(0);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() {
$(intobjs).reduce(new F2ReduceObjects<Integer>() {
@Override
public Integer f(Integer stack, Integer next) {
return stack + next;
}
}).get(0);
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() {
/*$(intobjs).staple(0, new F2ReduceObjects<Integer>() {
public Integer f(Integer left, Integer right) {
return left + right;
}
});*/
}
}, 10) + "µs");
System.out.println(benchmark(new F0() {
public void f() {
$(intobjs).delta(new F2DeltaObjects<Integer, Integer>() {
public Integer f(Integer left, Integer right) {
return right - left;
}