manojghosh has asked for the wisdom of the Perl Monks concerning the following question:

As i am using some win-api in perl prog., and used as Win32::API::Import->(). but my prog. takes lot of time in win-api function call. I want to know that anyone has used and know the performance of Win32::API::Prototype over this?
  • Comment on Performance diffrence in using Win32::API:: Import and win32::API::Prototype

Replies are listed 'Best First'.
Re: Performance diffrence in using Win32::API:: Import and win32::API::Prototype
by BrowserUk (Patriarch) on Mar 31, 2011 at 11:25 UTC

    Win32::API::Prototype and Win32::API::Import effectively do the same thing. They both export a sub into the callers name space that does:

    sub ApiName { return $globalHash{ 'ApiName' }->Call( @_ ); }

    The name of the global hash is different between the two packages, but the performance should be close to identical.

    You will get a minor performance gain by avoiding the import sub. Ie:

    usw Win32::API; my $api = Win32::API->new( 'dll', 'api', 'II', 'I' ) or die $^E; $api->Call( @_ );

    You avoid an extra level of perl subroutine call and a hash lookup. For all but the lowest cost APIs, the difference will be minimal, as most of the cost is in converting the call parameters to their C equivalents before calling into the DLL. It might make some perceptible difference for calls that take no perameters.

    If performance is a realistic consideration, you'd be better off writing Inline::C wrappers for the APIs you need.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Performance diffrence in using Win32::API:: Import and win32::API::Prototype
by bart (Canon) on Mar 31, 2011 at 12:08 UTC
    but my prog. takes lot of time in win-api function call
    If your program takes a lot of time calling the function, as I suspect, then you're barking up the wrong tree.

    The difference between the two is the declaration of the API function, which happens one time in your script (if you're doing it right). The difference between should be no more than, say, 100µSec. At worst.

    The calls to the function should be (close to) identical under the hood, so they should take virtually the same time.

Re: Performance diffrence in using Win32::API:: Import and win32::API::Prototype
by Anonymous Monk on Mar 31, 2011 at 11:01 UTC
    How about you? See Benchmark::cmpthese

    Seeing how Win32::API::Prototype is based on Win32::API, I don't expect there to be any time difference

Re: Performance diffrence in using Win32::API:: Import and win32::API::Prototype
by ikegami (Patriarch) on Mar 31, 2011 at 17:05 UTC
    Win32::API has a prototype interface as well. I find one must often treat pointers as numbers, so rather that faking a prototype, I usually use the letter notation.