java - What is the Fastest way to reorder an array -
what fastest (realtime data processing application) way reorder (the new indices same) array in java:
e.g.: have got: double[] = new double[] {1, 234, 12,99,0};
i need swiftly: double[] b = new double[] {a[2], a[4], a[0],a[1],a[3]};
but maybe this efficient way anyway?
many feedback
i doubt can better current approach of
double[] b = new double[] {a[2], a[4], a[0], a[1], a[3]};
likely candidates other sequences might forms of arrays.copyof
or arrays.copyofrange
, minimum amount of work must here consists of:
- create new array
- random access each element in array
there's small chance might better specific read/write orders (to take advantage of cache lines), 1 guess reads entirely in order , writes entire in ascending order:
double[] b = new double[a.length]; b[2] = a[0]; b[3] = a[1]; b[4] = a[3]; b[0] = a[2]; b[1] = a[4];
but don't have strong expectations of being noticeably better. if you're @ point you're trying eliminate or optimize on l1/l2 cache hits, it's time start micro-benchmarking, , real answer should experiment.
Comments
Post a Comment