Jump to content

Execution time problem


Recommended Posts

I moved the following script from one computer to another and the execution time increased from less than a second to more than two minutes. Does anyone have an idea why? The other computer is not a lot slower for other tasks.

The script looks at each pixel in a box, starting from the upper left and then continues row by row. For each pixel, it checks the color of the pixel and then calculates a value for the pixels brightness, and after that, if the brightness is above 130 it writes 255 255 255 (white) to a file or if it is less than 130, it writes 0 0 0 (black) to the same file.

When I tried this, a box 190 * 100 pixels took less than a second on one computer and more than two minutes on the other. Two minutes is painfully slow and I can't see why this happens. It's only 19000 loops, which should go quickly on a 1.8GHz dual core processor.

Func Pixels($x1, $y1, $x2, $y2)
    
    DirCreate("Temp")

    Local $writeString = ""
    
    $nrOfCols = $x2 - $x1 + 1
    $nrOfRows = $y2 - $y1 + 1

    $tempFile = FileOpen("Temp\temp.pnm", 2)
    FileWriteLine($tempFile, "P3")
    FileWriteLine($tempFile, $nrOfCols & " " & $nrOfRows)
    FileWriteLine($tempFile, "255")

    For $y = $y1 To $y2
        For $x = $x1 To $x2
            $color = PixelGetColor($x, $y)
            $red = BitShift(BitAND($color, 16711680), 16)
            $green = BitShift(BitAND($color, 65280), 8)
            $blue = BitAND($color, 255)
            $brightness = (0.3 * $red) + (0.59 * $green) + (0.11 * $blue)
            If $brightness > 130 Then
                $writeString &= " 255 255 255"
            Else
                $writeString &= " 0 0 0"
            EndIf
        Next
        FileWriteLine($tempFile, $writeString)
        $writeString = ""
    Next
EndFunc
Link to comment
Share on other sites

Func Pixels($x1, $y1, $x2, $y2)

What values you pass this function? Maybe they are related to resolution of the monitor?

I passed 542, 343, 732, 354. All well within the resolution of both computers.

do they have the same OS.?

cos if you have Aero theme on 1 pc, it makes ALOT of difference

I run Windows Vista on both. Same service packs, same version of Vista.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...