Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Fast execution

Fast execution

Scheduled Pinned Locked Moved C#
helpquestion
14 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sanforjackass
    wrote on last edited by
    #1

    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?

    S K L 3 Replies Last reply
    0
    • S sanforjackass

      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?

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      How slow is it? How many loops do you use? Considered reducing loops?

      sanforjackass wrote:

      there a way to make it works more faster?

      by first posting a code here, witch we do not know how to help you

      S 1 Reply Last reply
      0
      • S sanforjackass

        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?

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #3

        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.

        S 1 Reply Last reply
        0
        • S Saksida Bojan

          How slow is it? How many loops do you use? Considered reducing loops?

          sanforjackass wrote:

          there a way to make it works more faster?

          by first posting a code here, witch we do not know how to help you

          S Offline
          S Offline
          sanforjackass
          wrote on last edited by
          #4

          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.

          L K 2 Replies Last reply
          0
          • S sanforjackass

            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.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Are you using GetPixel?

            S R 2 Replies Last reply
            0
            • L Lost User

              Are you using GetPixel?

              S Offline
              S Offline
              sanforjackass
              wrote on last edited by
              #6

              yes

              L 1 Reply Last reply
              0
              • S sanforjackass

                yes

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Then that's the reason it's slow

                S 1 Reply Last reply
                0
                • S sanforjackass

                  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.

                  K Offline
                  K Offline
                  Keith Barrow
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • L Lost User

                    Then that's the reason it's slow

                    S Offline
                    S Offline
                    sanforjackass
                    wrote on last edited by
                    #9

                    and...

                    L 1 Reply Last reply
                    0
                    • S sanforjackass

                      and...

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Use lockbits (only once, outside the loops) and unsafe code

                      1 Reply Last reply
                      0
                      • L Lost User

                        Are you using GetPixel?

                        R Offline
                        R Offline
                        Rob Philpott
                        wrote on last edited by
                        #11

                        Good catch!

                        Regards, Rob Philpott.

                        L 1 Reply Last reply
                        0
                        • R Rob Philpott

                          Good catch!

                          Regards, Rob Philpott.

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Thanks, the first time I used pointers in C# was for this purpose, so I remember it well

                          1 Reply Last reply
                          0
                          • S sanforjackass

                            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?

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #13

                            yes[^]. :)

                            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.


                            1 Reply Last reply
                            0
                            • K Keith Barrow

                              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.

                              S Offline
                              S Offline
                              StarBP
                              wrote on last edited by
                              #14

                              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).

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups