Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Alternatives To Geo::Distance

by gray (Beadle)
on Oct 21, 2010 at 23:52 UTC ( [id://866666]=note: print w/replies, xml ) Need Help??


in reply to Alternatives To Geo::Distance

Speaking as the author of Geo-Distance-XS, I consider it to be actively developed. Even though Geo-Distance might be considered decommissioned by it's author, he probably will accept patches via its github repo. As will I for Geo::Distance::XS at its its repo.

A good reason to use Geo::Distance::XS:

---- [ Formula: hsin ] ------------------------------------ perl - distance from BWI to LAX: 2324.06319758555 miles xs - distance from BWI to LAX: 2324.06319758555 miles gis::fast - distance from BWI to LAX: 2324.06319758555 miles Benchmark: running gis::fast, perl, xs for at least 1 CPU seconds... gis::fast: 1 wallclock secs ( 1.05 usr + 0.01 sys = 1.06 CPU) @ 23 +866.04/s (n=25298) perl: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 78 +019.05/s (n=81920) xs: 2 wallclock secs ( 1.12 usr + -0.01 sys = 1.11 CPU) @ 12 +45236.94/s (n=1382213) Rate gis::fast perl xs gis::fast 23866/s -- -69% -98% perl 78019/s 227% -- -94% xs 1245237/s 5118% 1496% -- ---- [ Formula: polar ] ------------------------------------ perl - distance from BWI to LAX: 2652.59252292455 miles xs - distance from BWI to LAX: 2652.59252292455 miles gis::fast - distance from BWI to LAX: 2652.59252292455 miles Benchmark: running gis::fast, perl, xs for at least 1 CPU seconds... gis::fast: 1 wallclock secs ( 1.08 usr + 0.00 sys = 1.08 CPU) @ 18 +962.96/s (n=20480) perl: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 80 +736.45/s (n=86388) xs: 2 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 15 +09051.75/s (n=1720319) Rate gis::fast perl xs gis::fast 18963/s -- -77% -99% perl 80736/s 326% -- -95% xs 1509052/s 7858% 1769% -- ---- [ Formula: cos ] ------------------------------------ perl - distance from BWI to LAX: 2324.06319758555 miles xs - distance from BWI to LAX: 2324.06319758555 miles gis::fast - distance from BWI to LAX: 2324.06319758555 miles Benchmark: running gis::fast, perl, xs for at least 1 CPU seconds... gis::fast: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 23 +642.99/s (n=25298) perl: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 77 +282.08/s (n=81919) xs: 0 wallclock secs ( 1.00 usr + 0.00 sys = 1.00 CPU) @ 13 +10719.00/s (n=1310719) Rate gis::fast perl xs gis::fast 23643/s -- -69% -98% perl 77282/s 227% -- -94% xs 1310719/s 5444% 1596% -- ---- [ Formula: gcd ] ------------------------------------ perl - distance from BWI to LAX: 0 miles xs - distance from BWI to LAX: 2324.06319758555 miles gis::fast - distance from BWI to LAX: 0 miles Benchmark: running gis::fast, perl, xs for at least 1 CPU seconds... gis::fast: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 18 +270.09/s (n=19549) perl: 2 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 73 +080.37/s (n=78196) xs: 1 wallclock secs ( 1.05 usr + 0.01 sys = 1.06 CPU) @ 12 +98354.72/s (n=1376256) Rate gis::fast perl xs gis::fast 18270/s -- -75% -99% perl 73080/s 300% -- -94% xs 1298355/s 7006% 1677% -- ---- [ Formula: mt ] ------------------------------------ perl - distance from BWI to LAX: 2324.06319758555 miles xs - distance from BWI to LAX: 2324.06319758555 miles gis::fast - distance from BWI to LAX: 2324.06319758555 miles Benchmark: running gis::fast, perl, xs for at least 1 CPU seconds... gis::fast: 1 wallclock secs ( 1.12 usr + 0.01 sys = 1.13 CPU) @ 17 +300.00/s (n=19549) perl: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 67 +621.70/s (n=71679) xs: 2 wallclock secs ( 1.07 usr + 0.01 sys = 1.08 CPU) @ 12 +74311.11/s (n=1376256) Rate gis::fast perl xs gis::fast 17300/s -- -74% -99% perl 67622/s 291% -- -95% xs 1274311/s 7266% 1784% -- ---- [ Formula: tv ] ------------------------------------ perl - distance from BWI to LAX: 2328.95218785171 miles xs - distance from BWI to LAX: 2324.51147636132 miles gis::fast - distance from BWI to LAX: 2328.95218785171 miles Benchmark: running gis::fast, perl, xs for at least 1 CPU seconds... gis::fast: 2 wallclock secs ( 1.09 usr + 0.01 sys = 1.10 CPU) @ 21 +720.91/s (n=23893) perl: 1 wallclock secs ( 1.09 usr + 0.00 sys = 1.09 CPU) @ 16 +439.45/s (n=17919) xs: 2 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 77 +1011.43/s (n=809562) Rate perl gis::fast xs perl 16439/s -- -24% -98% gis::fast 21721/s 32% -- -97% xs 771011/s 4590% 3450% --
Benchmarking script:
#!/usr/bin/env perl use strict; use warnings; use Benchmark qw(cmpthese timethese); use Geo::Distance::XS; use GIS::Distance; # When benchmarking, need to have it call import/unimport before the # code is executed. my $orig_timethis_sub = \&Benchmark::timethis; { no warnings 'redefine'; *Benchmark::timethis = sub { my $sub = ('perl' eq $_[2] ? 'un' : '') . 'import'; Geo::Distance::XS->$sub(); $orig_timethis_sub->(@_); }; } # Lon, Lat my @coord = (-76.668851, 39.179689, -118.408618, 33.943532); my $geo = Geo::Distance->new; my $gis = GIS::Distance->new; my %gis_formula = ( hsin => 'Haversine', polar => 'Polar', cos => 'Cosine', gcd => 'GreatCircle', mt => 'MathTrig', tv => 'Vincenty', ); sub geo { my $d = $geo->distance(mile => @coord); } sub gis { my $d = $gis->distance(@coord[ 1, 0, 3, 2 ]); return $d->mile; } for my $formula (qw(hsin polar cos gcd mt tv)) { print "---- [ Formula: $formula ] -------------------------------- +----\n"; $geo->formula($formula); $gis->formula($gis_formula{$formula}); Geo::Distance::XS->unimport; printf "perl - distance from BWI to LAX: %s miles\n", geo(); Geo::Distance::XS->import; printf "xs - distance from BWI to LAX: %s miles\n", geo(); printf "gis::fast - distance from BWI to LAX: %s miles\n", gis(); print "\n"; my $benchmarks = timethese - 1, { perl => \&geo, xs => \&geo, 'gis::fast' => \&gis, }; cmpthese $benchmarks; print "\n"; }

Replies are listed 'Best First'.
Re^2: Alternatives To Geo::Distance
by Limbic~Region (Chancellor) on Oct 22, 2010 at 01:37 UTC
    gray,
    ...he probably will accept patches via

    I have emailed the author. I would like to offer a patch but I am not sure what the problem is. I was in a hurry to get my project complete so I could go to sleep.

    A good reason to use Geo::Distance::XS

    First, thanks! I admit that I didn't try it for a few reasons. The first is that I assumed one was just an XS implementation of the other to include the bug. The second reason is that in the environment where this needed to run, XS is not an easy option. Without going into a lot of detail - local politics have created technical hurdles I didn't want to jump through (I was tired). It is also the reason I didn't use GIS::Distance. I was pretty sure (and you confirmed) that it produces correct results but the litany of dependencies without an internet connection was unreasonable.

    I am happy that there are working solutions out there. I guess after reflecting on my lamentation, what I really should have asked is: Does anyone know of a Geo::Distance::Lite that works?

    Regarding your benchmark. First, I suspect you didn't "You can stick with the pure Perl version by setting the GEO_DISTANCE_PP environment variable before using this module" This is because Geo::Distance gave the correct answer which it I know it doesn't (the point of this thread). Second, it would only be fair to add tye's version which avoids the whole OO overhead.

    Cheers - L~R

      Regarding your benchmark. First, I suspect you didn't "You can stick with the pure Perl version by setting the GEO_DISTANCE_PP environment variable before using this module" This is because Geo::Distance gave the correct answer which it I know it doesn't (the point of this thread).

      $ENV{GEO_DISTANCE_PP} just triggers Geo::Distance::XS->unimport(), which my benchmark script calls directly. I also checked the results by hiding Geo::Distance::XS with Test-Without-Module and they were consistent. Note also the results for the 'gcd' formula- both Geo::Distance and GIS::Distance::Fast failed, whereas Geo::Distance::XS produced a reasonable result. Perhaps if you posted your test script we could dig further.

        gray,
        Perhaps if you posted your test script we could dig further.

        Without Geo::Distance::XS present.

        #!/usr/bin/perl use strict; use warnings; use Geo::Distance; my $geo = Geo::Distance->new; for (qw/tv hsin polar cos gcd mt/) { $geo->formula($_); print $_, " ", $geo->distance('mile', 39.175555,-76.671388 => 33.9 +42222,-118.407222), "\n"; } __DATA__ tv 9537.71241222878 hsin 2881.23714304656 polar 3114.47526297555 cos 2881.23714304656 gcd 12438.0476860875-9076.08896733252i mt 2881.23714304656

        Geo::Distance::XS
        use strict; use warnings; use Geo::Distance::XS; my $geo = Geo::Distance->new; for (qw/tv hsin polar cos gcd mt/) { $geo->formula($_); print $_, " ", $geo->distance('mile', 39.175555,-76.671388 => 33.9 +42222,-118.407222), "\n"; } __DATA__ tv 9538.66771882495 hsin 2881.23714304656 polar 3114.47526297555 cos 2881.23714304656 gcd 2881.23714304656 mt 2881.23714304656
        Update: Ok, I am a freaking idiot who should not write code while up late at night. I swapped long/lat. This was further complicated by tye's method having in the same order as I was using which produces the correct result. I need to have my JAPH card revoked. Please forgive my gigantic stupidity.

        Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found