Fast execution
-
my program to search for an object in photo with ROI algorithm, that means i have to make two loops for the photo and two for the mask.
-
yes
-
yes
-
my program to search for an object in photo with ROI algorithm, that means i have to make two loops for the photo and two for the mask.
This is going to be a slow process, due to the size of the photo files and the complexity of what is being done. I suggest Parallelising the top level loop (the one that processes each photo in turn) so that you process multiple photos at the same time. If you can, consider parallelise the inner loops as well. Naturally this will make the code harder to understand. There is a pdf knocking around introducing parallel extensions in .net 4, written by Daniel Moth. It is actually a good introduction to parallelism, and will help you design your code with the extensions in mind. [Edit] -- Or -- Do what Harold Suggests first!
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
modified on Thursday, March 11, 2010 5:46 AM
-
and...
-
and...
-
Good catch!
Regards, Rob Philpott.
-
Good catch!
Regards, Rob Philpott.
-
i make a program that use four for loops, and there is no error but! the program is too slow, i tried to make it in library, it make it a little more faster but not that faster, is there a way to make it works more faster?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
sanforjackass wrote:
it make it a little more faster but not that faster, is there a way to make it works more faster?
Withous seeing what the code does, IMO you've three real options:
- Refactor to run in parallel. This is only an option if the order things are processed in does (or can be made to) not matter
- Re-implement using pointers. This will work best if one of the lists/collections you are itering over is long and the processing task is short-lived
- Profile the code and optimize the task that is taking the most time.
It might be helpful if you post code, of give psuedo-code about what you application is actually doing.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
IMO do the second tip first (MAJOR speed increase, between 5 and 100 times), then do the first one (speed increase depends on the processor, best-case scenario is 1x extra increase for each processor core [such as 4x for a 4-core processor]). After those two major optimizations (Use .NET 4.0 Beta's Parallel.For method for the first tip), profile the code (NProf is a good sampling profiler, also Visual Studio 2010 Beta 2 [free to use until June] comes with an excellent profiler. If you have the money, use ANTS, as I have heard only good things about it) and fix the bottlenecks (those areas that take the most time).