Want to know the difference?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rishabh
Posts: 11
Joined: 2016-03-28T02:33:43-07:00
Authentication code: 1151

Want to know the difference?

Post 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??
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Want to know the difference?

Post 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.
rishabh
Posts: 11
Joined: 2016-03-28T02:33:43-07:00
Authentication code: 1151

Re: Want to know the difference?

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Want to know the difference?

Post 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.
snibgo's IM pages: im.snibgo.com
rishabh
Posts: 11
Joined: 2016-03-28T02:33:43-07:00
Authentication code: 1151

Re: Want to know the difference?

Post by rishabh »

Thanks for the reply . It really helps . I will test it with large number of objects. Thank you
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Want to know the difference?

Post 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
snibgo's IM pages: im.snibgo.com
rishabh
Posts: 11
Joined: 2016-03-28T02:33:43-07:00
Authentication code: 1151

Re: Want to know the difference?

Post by rishabh »

Hi snibgo,

Thanks for the reply. It was really helpful.
Post Reply