Code snipet for Histogram

While working on the next code update, the code example below raised some eyebrows. How much time does it take to compute equidistant histogram? It turnes out, that our old code needed about 3x more time than array copy operation. The current version is a near match, being only 10% slower than best optimized array copy:

        while not Data.BlockEnd do
            aData.ThresholdGT_LT(Data,Max,Max,Min, Min);
            aData.Normalize(aData, Min, BinWidth);
            aData.CopyTo(intData, TRounding.rnTrunc);
            HistoCount(intData.IData, intData.DataIndex(0), Results.IData, Results.dataIndex(0), intData.Length);
//Old code:
//        for i:=0 to Data.Length-1 do
//        begin
//          j:= Trunc((Data.Values[i]-Min)*InvBinWidth); // was round
//          if (j < 0) then Inc(leftTail)
//          else if (j >= NumBins) then Inc(righttail)
//          else Results.IValues[j] := Results.IValues[j] + 1;
//        end;
While the vectorization seems dominating, it brings only 20% speedup. The other 250% come in to effect only after block processing is applied. (BlockInit, BlockNext, BlockEnd).

  • Created on .

© DewResearch 1997 - 2022 All Rights Reserved.

E-mail This email address is being protected from spambots. You need JavaScript enabled to view it..
Delphi & C++ Builder are registered trademarks of Embarcadero Corporation. All other brands and product names are trademarks or registered trademarks of their respective owners.