richardstartin commented on pull request #7487: URL: https://github.com/apache/pinot/pull/7487#issuecomment-927795364
Here's a quick comparison to show what's at stake here (I don't think the benchmark is worth maintaining in this project). Note that I selected lengths which aren't aligned to make sure slower tails of loops execute, which won't happen on aligned inputs. ```java @State(Scope.Benchmark) public class BenchmarkByteArrayCompare { @Param({"7", "31", "1023"}) int _length; @Param("1") int _offset; private byte[] _left; private byte[] _right; @Setup(Level.Trial) public void setup() { _left = new byte[_length]; ThreadLocalRandom.current().nextBytes(_left); _right = Arrays.copyOf(_left, _left.length); _right[_right.length - _offset] = (byte) ~_left[_left.length - _offset]; } @Benchmark public int compare() { return ByteArray.compare(_left, _right); } } ``` ``` Benchmark (_length) (_offset) Mode Cnt Score Error Units BenchmarkByteArrayCompare.compare 7 1 avgt 5 5.942 ± 0.048 ns/op BenchmarkByteArrayCompare.compare 31 1 avgt 5 15.298 ± 1.040 ns/op BenchmarkByteArrayCompare.compare 1023 1 avgt 5 320.390 ± 1.262 ns/op Benchmark (_length) (_offset) Mode Cnt Score Error Units BenchmarkByteArrayCompare.compare 7 1 avgt 5 7.913 ± 0.174 ns/op BenchmarkByteArrayCompare.compare 31 1 avgt 5 8.351 ± 0.016 ns/op BenchmarkByteArrayCompare.compare 1023 1 avgt 5 22.765 ± 1.566 ns/op ``` For inputs shorter than 8 bytes, there is a small setup cost of the order of 1ns, but for larger inputs the improvement is huge. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org