I made the code below to test which is faster, sqrt or using a lookup table with a ton of random floats and it turns out the first method, the function named method1 is faster. Is it because of caching or what.
Hi lostwithcpp, i think it could be because you use vector < vector < vector <float > > > distance, which is a very expensive data structure.
Try converting this distance 3D vector into 1D array: float* distance.
Besides, since you are using different operations:
method1: conversion, /, +
method2: %
There could lead to some discrepancy, but not so much anyway.