Alternative to num2str when looking up in containers.Map (performance)
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have implemented A* for x,y grid maps. I use two containers.Map to keep track of visited nodes and running cost, since containers.Map seemed nice to work with as similar to dictionaries.
My key for the containers.Map are the x,y coordinates of visited nodes. I have my nodes as a vector when I use them, i.e. startNode = [x y].
When I want to use them as a key for the containers.Map, I use num2str lige in the following
startNode = [1 1];
currentCost = containers.Map;
currentCost[num2str(startNode)] = 0;
It works really fine, except that I have num2str in my inner loop of the algorithm, and hence it can be called many many times e.g. 600.000-700.000 times. According to profiler num2str (and hence int2str) amounts to 50-75% of the overall processing time.
I have already optimized the code some, and was able to place some of the num2str calls outside the inner loop, which reduced the amount of calls by 60%, which is what amounts to the above mentioned 50-75%.
I am looking for some suggestions and ideas to what I could use, either instead of num2str that would have a better performance, and still be able to work with containers.Map, or perhaps a different approach, which could work just as well instead of containers.Map, but perhaps just use the node vector itself [x y], without converting it to a string? Note, I do the conversion because the key for containers.Map must be a string.
Best regards
0 件のコメント
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!