which has better overall performance in this implementation?
between method1 and method2 which has better performance and lower overhead?
ChatGPT says method1 is slightly cheaper but Gemini says method2 is better.
(dont complain about semikolons in the comments, its harder to know if this line is the end of the statement or if it continues in the next line)
@file:JvmName("Suppliers")
import java.util.function.IntSupplier;
@JvmSynthetic
@JvmName("_intSupplierOf")
inline fun intSupplierOf(value: Int): IntSupplier = IntSupplier { value };
@JvmName("intSupplierOf")
fun _intSupplierOf(value: Int): IntSupplier = IntSupplier { value };
class Test {
fun method1(): Int {
val x = intSupplierOf(3);
return x.getAsInt();
}
fun method2(): Int {
val x = _intSupplierOf(3);
return x.getAsInt();
}
}
decompiled Java code for reference:
public final class Suppliers {
// $FF: synthetic method
@JvmName(
name = "_intSupplierOf"
)
public static final IntSupplier _intSupplierOf(final int value) {
int $i$f$_intSupplierOf = 0;
return new IntSupplier() {
public final int getAsInt() {
return value;
}
};
}
@JvmName(
name = "intSupplierOf"
)
@NotNull
public static final IntSupplier intSupplierOf(int value) {
return Suppliers::_intSupplierOf$lambda$0;
}
private static final int _intSupplierOf$lambda$0(int $value) {
return $value;
}
}
public final class Test {
public final int method1() {
int value$iv = 3;
int $i$f$_intSupplierOf = false;
IntSupplier x = (IntSupplier)(new 1(value$iv));
return x.getAsInt();
}
public final int method2() {
IntSupplier x = Suppliers.intSupplierOf(3);
return x.getAsInt();
}
}