Loops over huge lists for histogram

Hi everyone,
I suspect the answer to my question lies in scripting, for which I have no knowledge or experience.
I have a very very long list of points (1,214,208 of them exactly). For each one of these points, I need to find the closest point from another list of 16 “reference points”. Then I count how many time each “reference point” is returned and try to draw an histogram of that.
I got a solution that use a slider to go through my many points and return for each the index of the Reference point. But looping this over would be disastrously long. I tried with “animating” the slider but it seems to jump steps and the slider won’t go over 1,000,000 values.
This seems simple but I can’t seem to resolve it in GHPython or C#.
Many thanks!

something like this?

Thanks Gijs,

That looks exactly what I was looking for!

Will try shortly and let you know.