Optimizing ‘new byte[]’
How much time does it take to allocate a byte array? Let’s write a JMH benchmark: @Param({"1000", "10000", "100000"}) int size; @Benchmark public void newByteArray() { byte[] bytes = new byte[size]; bytes[bytes.length - 1] = 'a'; }Running this on my laptop shows that time scales with size: size…