
Hi! Profiling says that my program spends 18.4 % of time (that is around three seconds) and 18.3 % of allocations in this function which is saving the rendered image to a PPM file: saveImageList :: String -> Int -> Int -> [ViewportDotColor] -> IO () saveImageList filename width height image = do B.writeFile filename file where file = B.append header bytes header = C.pack $ "P6\n" ++ show width ++ " " ++ show height ++ "\n255\n" bytes = B.pack $ concatMap (color . dealpha . (\(ViewportDotColor _ c) -> c)) image where color (VoxelColor red green blue _) = [floor $ red * 255, floor $ green * 255, floor $ blue * 255] dealpha c = addColor c (VoxelColor 1.0 1.0 1.0 1.0) -- white background For a 921615 bytes large file to save this is too much in my opinion. And I think that it consumes to much allocations. Probably it should not store intermediate lists? Any suggestions? Best regards Mitar

Maybe your image isn't strict enough and the computations are forced when the image gets written to disc? Am 20.07.2008 um 14:13 schrieb Mitar:
Hi!
Profiling says that my program spends 18.4 % of time (that is around three seconds) and 18.3 % of allocations in this function which is saving the rendered image to a PPM file:
saveImageList :: String -> Int -> Int -> [ViewportDotColor] -> IO () saveImageList filename width height image = do B.writeFile filename file where file = B.append header bytes header = C.pack $ "P6\n" ++ show width ++ " " ++ show height ++ "\n255\n" bytes = B.pack $ concatMap (color . dealpha . (\(ViewportDotColor _ c) -> c)) image where color (VoxelColor red green blue _) = [floor $ red * 255, floor $ green * 255, floor $ blue * 255] dealpha c = addColor c (VoxelColor 1.0 1.0 1.0 1.0) -- white background
For a 921615 bytes large file to save this is too much in my opinion. And I think that it consumes to much allocations. Probably it should not store intermediate lists?
Any suggestions?
Best regards
Mitar _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi!
2008/7/20 Adrian Neumann
Maybe your image isn't strict enough and the computations are forced when the image gets written to disc?
But it still takes three seconds more than displaying to the screen. This is why I am also thinking that this code is to slow. This and that when saving to a file it takes almost 25 % more allocations. So probably it is slower because of all this allocations? Mitar

mmitar:
Hi!
Profiling says that my program spends 18.4 % of time (that is around three seconds) and 18.3 % of allocations in this function which is saving the rendered image to a PPM file:
saveImageList :: String -> Int -> Int -> [ViewportDotColor] -> IO () saveImageList filename width height image = do B.writeFile filename file
where file = B.append header bytes header = C.pack $ "P6\n" ++ show width ++ " " ++ show height ++ "\n255\n"
bytes = B.pack $ concatMap (color . dealpha . (\(ViewportDotColor _ c) -> c)) image where color (VoxelColor red green blue _) = [floor $ red * 255, floor $ green * 255, floor $ blue * 255] dealpha c = addColor c (VoxelColor 1.0 1.0 1.0 1.0) -- white background
For a 921615 bytes large file to save this is too much in my opinion. And I think that it consumes to much allocations. Probably it should not store intermediate lists?
Rather than generating the bytes as a list and packing them, could you instead fill a bytestring directly? -- Don
participants (3)
-
Adrian Neumann
-
Don Stewart
-
Mitar