Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: A better mod (%) operator?

by tadman (Prior)
on Jul 08, 2002 at 21:15 UTC ( [id://180326]=note: print w/replies, xml ) Need Help??


in reply to A better mod (%) operator?

There's nothing to stop you from using Inline::C, with assembler, to make it all happen. The catch is that you have to construct an array which you return to Perl, so it would be wise to read up on how XS works. The thing is, though, that the cost of manufacturing an array vastly exceeds any speed gain you'd get by using inline assembler. These days, division isn't nearly as expensive as it used to be, and memory is often the bottleneck.

I think if you're that concerned about speed, though, you wouldn't be using Perl anyway. You'd be using C, or C++, or possibly even FORTRAN.

Replies are listed 'Best First'.
Re: Re: A better mod (%) operator?
by BrowserUk (Patriarch) on Jul 09, 2002 at 00:11 UTC

    It wasn't really a "search for speed" that drove the thought, it was more elegance, orthogonality and that it bugs me that I know that the 'other part of the equation' is sitting there in a register somewhere but I have to do the division again to get it.

    Down the years, It seems that almost every time I have made use of the mod operator, I have also done a div with the same parameters.

    Finally using Perl, I have a language that could elegantly provide me with both halves of the equation in one pass and render the elegance that comes with it.

    I hadn't thought about the expense of constructing the return list. Is it possible to "re-use" the inbound @_ list? Would there be any benefit in doing so?

    I wonder how constructing a new list would compare (at the inner levels) with duplicating the whole inbound/outbound stack frames etc.? Possibly little in it?

    Basically, I don't yet know enough to judge and am not ready to go digging deep enough to get the answers.

    T'was just an idea:^).

Re: Re: A better mod (%) operator?
by samtregar (Abbot) on Jul 08, 2002 at 21:34 UTC
    Or better yet, Inline::ASM.

    But I agree with your other statements - I'd be very surprised to find a Perl program where a division operation was a significant bottleneck.

    -sam

      From the Inline::ASM documentation:
      WARNING

      Do NOT use assembler to write Perl extensions! It's sick and wrong!
      Better. Evil. Muhahaha.

        Saw that too. Begs the question: Why does it exist?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180326]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found