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