diff --git a/elastiknn-api4s/src/main/java/com/klibisz/elastiknn/api/FloatArrayBuffer.java b/elastiknn-api4s/src/main/java/com/klibisz/elastiknn/api/FloatArrayBuffer.java index 3e8dec688..60b7b9c76 100644 --- a/elastiknn-api4s/src/main/java/com/klibisz/elastiknn/api/FloatArrayBuffer.java +++ b/elastiknn-api4s/src/main/java/com/klibisz/elastiknn/api/FloatArrayBuffer.java @@ -21,18 +21,19 @@ public FloatArrayBuffer() { } public void append(float f) { - // TODO: Test whether try/catch is faster than if. -// try { -// this.array[index++] = f; -// } catch (IndexOutOfBoundsException ex) { -// this.array = Arrays.copyOf(this.array, this.array.length * 2); -// this.array[index - 1] = f; -// } + // if statement gets about 557013.799 ops/s on r6i.4xlarge. if (index == this.array.length) { // System.out.printf("Growing from %d to %d\n", this.array.length, this.array.length * 2); this.array = Arrays.copyOf(this.array, this.array.length * 2); } this.array[index++] = f; + // try/catch gets ... + try { + this.array[index++] = f; + } catch (IndexOutOfBoundsException ex) { + this.array = Arrays.copyOf(this.array, this.array.length * 2); + this.array[index - 1] = f; + } } public float[] toArray() {