Page 1 of 1

Want to know the difference?

Posted: 2016-03-28T02:41:02-07:00
by rishabh
What is the difference between 1 and 2?
1. convert abc.png -draw "fill black rectangle 232,689,1843,1154" -draw "fill black rectangle 23,69,143,154" abc_result.tiff
2. convert abc.png -draw "fill black rectangle 232,689,1843,1154 fill black rectangle 23,69,143,154" abc_result.tiff

if i use draw command twice or more will it create performance delay or works as same??

Re: Want to know the difference?

Posted: 2016-03-28T03:02:56-07:00
by Bonzo
Do both commands work?

If it was me I would run a test with a timer and see if there was a speed difference.

Re: Want to know the difference?

Posted: 2016-03-28T06:33:08-07:00
by rishabh
Hello,

Yes both command works . I just need to understand which is the most efficient method to do so?
1. give all co-ordinates in one -draw
2. give co-ordinates separately.
I ran the test with different type of images and checked out time but it is not very concrete and vary but with very very large number of conversion this may effect the performance.I don't have huge amount of data. but still what is the best practice to invoke -draw?

So please help me to know which is the best practice to invoke the command and why?
Thanks.

Re: Want to know the difference?

Posted: 2016-03-28T08:08:31-07:00
by snibgo
I expect the second method, with a single "-draw", is slightly faster. If this is important, you'll need to measure it. You may find the performance difference only becomes apparent with hundreds of small drawn objects.

Re: Want to know the difference?

Posted: 2016-03-28T20:58:45-07:00
by rishabh
Thanks for the reply . It really helps . I will test it with large number of objects. Thank you

Re: Want to know the difference?

Posted: 2016-03-29T14:13:11-07:00
by snibgo
I've done a timing test.

Case 1:

Code: Select all

-draw "fill red rectangle 10,10,12,12"
-draw "fill red rectangle 100,100,102,102"
This was done 50,000 times in a single convert. It took 11 seconds.

Case 2:

Code: Select all

fill red rectangle 10,10,12,12
fill red rectangle 100,100,102,102
This was done 50,000 times in a single "-draw" in a convert. It took 2 seconds.

I'm surprised at how large the difference is. The "-draw" itself has a large overhead, and better performance comes from combining multiple draws into one.

In this test, my drawn objects are deliberately small. When they are larger, the speed improvement is far less. For example, ten thousand 20x20 rectangles have timings of 9 seconds and 7 seconds.

The full Windows BAT script for my test was:

Code: Select all

%IM%convert -size 300x300 xc:White ds.png

echo ds.png >ds.scr

echo off 
( for /L %%i in (1,1,50000) do (
    echo -draw "fill red rectangle 10,10,12,12"
    echo -draw "fill red rectangle 100,100,102,102"
  )
) >>ds.scr

echo on

call StopWatch
%IM%convert "@ds.scr" NULL:
call StopWatch


del ds2.scr

echo off 
( for /L %%i in (1,1,50000) do (
    echo fill red rectangle 10,10,12,12
    echo fill red rectangle 100,100,102,102
  )
) >>ds2.scr

echo on

call StopWatch
%IM%convert ds.png -draw "@ds2.scr" NULL:
call StopWatch

Re: Want to know the difference?

Posted: 2016-03-29T22:11:56-07:00
by rishabh
Hi snibgo,

Thanks for the reply. It was really helpful.