private static BinaryArray fromPrimitiveArray(Object arr, int offset, int length, Field field) {
    BinaryArray result = new BinaryArray(field);
    final long headerInBytes = calculateHeaderInBytes(length);
    final long valueRegionInBytes = result.elementSize * length;
    final long totalSize = headerInBytes + valueRegionInBytes;
    if (totalSize > Integer.MAX_VALUE) {
      throw new UnsupportedOperationException(
          "Cannot convert this array to binary format as " + "it's too big.");
    }

    final byte[] data = new byte[(int) totalSize];
    Platform.putLong(data, Platform.BYTE_ARRAY_OFFSET, length);
    Platform.copyMemory(
        arr, offset, data, Platform.BYTE_ARRAY_OFFSET + headerInBytes, valueRegionInBytes);

    MemoryBuffer memoryBuffer = MemoryUtils.wrap(data);
    result.pointTo(memoryBuffer, 0, (int) totalSize);
    return result;
  }
@Test(enabled = false)
  public void testAccessPerf() {
    int length = 10000;
    int[] arr = new int[length];
    Random random = new Random();
    for (int i = 0; i < length; i++) {
      arr[i] = random.nextInt();
    }
    BinaryArray binaryArray = BinaryArray.fromPrimitiveArray(arr);
    int iterNums = 100_000;

    // warm
    for (int i = 0; i < iterNums; i++) {
      for (int j = 0; j < length; j++) {
        elem = arr[j];
      }
    }
    // test array
    long startTime = System.nanoTime();
    for (int i = 0; i < iterNums; i++) {
      for (int j = 0; j < length; j++) {
        elem = arr[j];
      }
    }
    long duration = System.nanoTime() - startTime;
    LOG.info("access array take " + duration + "ns, " + duration / 1000_000 + " ms\n");

    for (int i = 0; i < iterNums; i++) {
      for (int j = 0; j < length; j++) {
        elem = binaryArray.getInt32(j);
      }
    }
    // test binary array
    startTime = System.nanoTime();
    for (int i = 0; i < iterNums; i++) {
      for (int j = 0; j < length; j++) {
        elem = binaryArray.getInt32(j);
      }
    }
    duration = System.nanoTime() - startTime;
    LOG.info("access BinaryArray take " + duration + "ns, " + duration / 1000_000 + " ms\n");
  }