As you can see in the next pprof release, I have these nested for loops that take up most of my program time. The source is in golang, but the code is explained below:
8.55mins 1.18hrs 20: for k := range mapSource {
4.41mins 1.20hrs 21: if positions, found := mapTarget[k]; found {
. . 22:
1.05mins 1.05mins 23: for _, targetPos := range positions {
2.25mins 2.33mins 24: for _, sourcePos := range mapSource[k] {
1.28s 15.78s 25: matches = append(matches, match{int32(targetPos), int32(sourcePos)})
. . 26: }
. . 27: }
. . 28: }
. . 29: }
I am currently using 2 map[int32][]int32, targetMap and sourceMap.
These cards contain an array from int for the given key. Now I want to find the keys that match on both cards and store the combinations of elements in arrays.
So for example:
sourceMap[1] = [3,4]
sourceMap[5] = [9,10]
targetMap[1] = [1,2,3]
targetMap[2] = [2,3]
targetMap[3] = [1,2]
The only thing in common is 1, and the result will be[(3,1), (3,2), (3,3), (4,1), (4,2), (4,3)]
Is there any possible way (a more suitable data structure or something else) that can improve the speed of my program?
1000 150000 , .
EDIT: Concurrency , .