Created
October 25, 2021 10:04
-
-
Save amaembo/371aa7fb7ae472bb5a671ecf6dfa46f0 to your computer and use it in GitHub Desktop.
MemoryTest sample
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
import java.util.ArrayList; | |
public class MemoryTest { | |
public static void main(String[] args) { | |
var processors = new ArrayList<Processor>(); | |
for (int i = 0; i < 1000; i++) { | |
int[] data = new int[10_000_000]; | |
processors.add(new Processor(data) { | |
@Override | |
int calculate() { | |
return length; | |
} | |
}); | |
} | |
System.out.println(processors.stream().mapToLong(Processor::calculate).sum()); | |
} | |
} | |
abstract class Processor { | |
int length; | |
Processor(int[] data) { | |
length = data.length; | |
} | |
abstract int calculate(); | |
} |
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
import java.util.ArrayList | |
import kotlin.jvm.JvmStatic | |
import java.util.function.ToLongFunction | |
object MemoryTest { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
val processors = ArrayList<Processor>() | |
for (i in 0..999) { | |
val data = IntArray(10000000) | |
processors.add(object : Processor(data) { | |
override fun calculate(): Int { | |
return length | |
} | |
}) | |
} | |
println(processors.stream().mapToLong { obj: Processor -> | |
obj.calculate() | |
.toLong() | |
}.sum()) | |
} | |
} | |
internal abstract class Processor(data: IntArray) { | |
var length: Int | |
init { | |
length = data.size | |
} | |
abstract fun calculate(): Int | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment