handiklap
08-10-2006, 02:58 PM
I'm looking to optimize some overnight rendering/comp scripts which are sometimes not quick enough to finish a queue (48 or so) of images (1575x1250 & 2400x1575) before 8am rolls around. What I'm wondering is which, if either, of the two bits of code should technically be more efficient.
Some background info:
- ambientPass, occlusionPass and comp1 are bitmap values with identical dimensions.
- overlayBlend is a function which composites 2 pixels and returns a pixel color value.
Code sample 1:
for j=0 to ambientPass.height-1 do
(
for i=0 to ambientPass.width-1 do
(
ambientPixel = getPixels ambientPass [i,j] 1
occlusionPixel = getPixels occlusionPass [i,j] 1
outputPixel = overlayBlend ambientPixel[1] occlusionPixel[1]
outputPixel = #(outputPixel)
setPixels comp1 [i,j] outputPixel
)
)
Code sample 2:
for j=0 to ambientPass.height-1 do
(
ambientPixels = getPixels ambientPass [0,j] ambientPass.width
occlusionPixels = getPixels occlusionPass [0,j] ambientPass.width
outputPixel = #()
for i=1 to ambientPass.width do
(
append outputPixel (overlayBlend ambientPixels[i] occlusionPixels[i])
setPixels comp1 [0,j] outputPixel
)
)
As you can see, the difference between the two is that in sample 1, the pixels are collected one at a time, while in sample 2 an entire row of pixels is collected at a time. Am I correct in assuming sample 2 would be the most efficient? I realize that collecting outside of the nested loop is much quicker, as I'm collecting only once per row of pixels, but I just wanted some verification that I'm not overlooking something that would negate this. Also, considering that this block of code, in one incarnation or another, is executed 3 times for each image, how significant would the difference in render time be on a set of 48 images?
Some background info:
- ambientPass, occlusionPass and comp1 are bitmap values with identical dimensions.
- overlayBlend is a function which composites 2 pixels and returns a pixel color value.
Code sample 1:
for j=0 to ambientPass.height-1 do
(
for i=0 to ambientPass.width-1 do
(
ambientPixel = getPixels ambientPass [i,j] 1
occlusionPixel = getPixels occlusionPass [i,j] 1
outputPixel = overlayBlend ambientPixel[1] occlusionPixel[1]
outputPixel = #(outputPixel)
setPixels comp1 [i,j] outputPixel
)
)
Code sample 2:
for j=0 to ambientPass.height-1 do
(
ambientPixels = getPixels ambientPass [0,j] ambientPass.width
occlusionPixels = getPixels occlusionPass [0,j] ambientPass.width
outputPixel = #()
for i=1 to ambientPass.width do
(
append outputPixel (overlayBlend ambientPixels[i] occlusionPixels[i])
setPixels comp1 [0,j] outputPixel
)
)
As you can see, the difference between the two is that in sample 1, the pixels are collected one at a time, while in sample 2 an entire row of pixels is collected at a time. Am I correct in assuming sample 2 would be the most efficient? I realize that collecting outside of the nested loop is much quicker, as I'm collecting only once per row of pixels, but I just wanted some verification that I'm not overlooking something that would negate this. Also, considering that this block of code, in one incarnation or another, is executed 3 times for each image, how significant would the difference in render time be on a set of 48 images?
