Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Bidirectional lookup algorithm? (poor XS solution)

by shmem (Chancellor)
on Jan 11, 2015 at 20:27 UTC ( [id://1112906]=note: print w/replies, xml ) Need Help??


in reply to Re: Bidirectional lookup algorithm? (Solution.)
in thread Bidirectional lookup algorithm? (Updated: further info.)

That line below your signature is somewhat enigmatic:

The code present a class:BiMap, which supports the following methods: 7 ) { strncpy( (char*)( iHash script for RAD and testing), and a brief description. , CLEAN_AFTER_BUILD =used, newSize ); for( i = 0; i = pair; bm--1

I've tried setting up a bidirectional hash using XS code. It makes both key and values into keys and misuses the IV slot of SV of a hash entry to store the pointer to the crossover hash key.

However, the benchmarks are disappointing:

use blib; use Hash::Bidirectional; use Benchmark qw(cmpthese); use Devel::Size qw(total_size); use strict; use warnings; my $hn = {}; my $hb = bless {}, 'Hash::Bidirectional'; my $i = 0; for ( 'aaaaz' .. 'zzzzz') { $i++; $hn->{$_} = $i; # - normal hash $hn->{$i} = $_; # / $hb->pair($_,$i); # - bidirectional hash } print "size normal hash: ", total_size($hn),"\n"; print "size bi_dir hash: ", total_size($hb),"\n"; cmpthese( 10000000, { normal => sub { $hn->{$hn->{shmem}} }, bi_dir => sub { $hb->get($hb->get('shmem')) }, }); __END__ size normal hash: 3025679168 size bi_dir hash: 2360323536 Rate bi_dir normal bi_dir 2801120/s -- -62% normal 7407407/s 164% --

Improvement of 22% in memory and more than double time for lookup? Why? Is it due to method call/XS overhead? XS code below.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^3: Bidirectional lookup algorithm? (poor XS solution)
by BrowserUk (Patriarch) on Jan 11, 2015 at 21:48 UTC
    That line below your signature is somewhat enigmatic:

    It's an automatic appending of a collection of random snippets from the body of the post. It happens quite often when I post here. I try to remember to check for them and remove them; but sometimes I forget.

    I'm told (by the PMDevs) that it is due to the browser I use -- Opera -- but the fact that it never happens on any other site I use makes me think it is more to do with PM than Opera; but its always easier to blame someone else's tools than fix your own code.

    more than double time for lookup? Why? Is it due to method call/XS overhead?

    I would assume so. Any XS code is always going to be at a disadvantage compared to built-ins; that's inevitable. Which means you really have to parr everything down to even begin to compete.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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. Agile (and TDD) debunked

      I'm told (by the PMDevs) that it is due to the browser I use -- Opera -- but the fact that it never happens on any other site I use makes me think it is more to do with PM than Opera; but its always easier to blame someone else's tools than fix your own code.

      :) do you got any js in your free nodelet?

      I've been using perlmonks since 2001 and this appending of random snippets hasn't happened to me, but then I don't use opera :/

        :) do you got any js in your free nodelet?

        What's a "free nodelet"? :)

        Seems I do have one, and there was some js there; though it only seemed to be loading some 3rd party js; not actually executing it. (Not sure how, why or when it got there.)

        But in any case, I don't have the free nodelet enable either on the frontpage or anywhere else, so it seems unlikely that is the cause.

        I have seen the effect -- random crap at the end of the post -- on 2 or 3 nodes by other people, but I don't remember who, or which nodes. But they might well have also been Opera users.

        It really is weird, in that it has persisted across several new versions of Opera -- which if it is an Opera bug, you'd think it would have been caught and dealt with by now -- and has never occurred anywhere else than this site.

        (Notice the bar 'li' after my sig. I didn't type it, it was there as soon as the "Comment on" TEXTAREA was displayed. And it isn't in my template.

        (Update: And now I've hit "Create" and "update" once, its been joined by the link test from my footer.)

        (Update again: And after hitting "update" to add the line above, its been joined by the text: 'free nodelet')


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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. Agile (and TDD) debunked

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found