[QUIZ] IP to Country (#139) - RUBY

This is a discussion on [QUIZ] IP to Country (#139) - RUBY ; The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz by submitting ideas as often as ...

+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 38

[QUIZ] IP to Country (#139)

  1. Default [QUIZ] IP to Country (#139)

    The three rules of Ruby Quiz:

    1. Please do not post any solutions or spoiler discussion for this quiz until
    48 hours have passed from the time on this message.

    2. Support Ruby Quiz by submitting ideas as often as you can:

    http://www.rubyquiz.com/

    3. Enjoy!

    Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
    on Ruby Talk follow the discussion. Please reply to the original quiz message,
    if you can.

    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    This week's Ruby Quiz is to write a simple utility. Your program should accept
    an IP address as a command-line argument and print out the two letter code for
    the country that IP is assigned in. You can find a database for the matching
    at:

    http://software77.net/cgi-bin/ip-country/geo-ip.pl

    To keep the problem interesting though, let's write our programs with a focus on
    speed and memory efficiency.

    $ time ruby ip_to_country.rb 68.97.89.187
    US

    real 0m0.314s
    user 0m0.259s
    sys 0m0.053s


  2. Default Re: [QUIZ] IP to Country (#139)

    Ruby Quiz wrote:
    > [...]
    >
    > $ time ruby ip_to_country.rb 68.97.89.187
    > US
    >
    > real 0m0.314s
    > user 0m0.259s
    > sys 0m0.053s


    Is an 'initialisation run' allowed to massage the data?
    (we should at least split the benchmarks to keep it fair)

    Is it motivating or a spoiler to post timings?

    cheers

    Simon




  3. Default Re: [QUIZ] IP to Country (#139)

    On Sep 14, 2007, at 2:20 PM, Simon Kr=F6ger wrote:

    > Ruby Quiz wrote:
    >> [...]
    >>
    >> $ time ruby ip_to_country.rb 68.97.89.187
    >> US
    >> =09
    >> real 0m0.314s
    >> user 0m0.259s
    >> sys 0m0.053s

    >
    > Is an 'initialisation run' allowed to massage the data?
    > (we should at least split the benchmarks to keep it fair)


    My script does need and initialization run, yes. I don't see any =20
    harm in paying a one time penalty to set things up right.

    > Is it motivating or a spoiler to post timings?


    Motivating, definitely.

    James Edward Gray II=


  4. Default Re: [QUIZ] IP to Country (#139)

    James Edward Gray II wrote:
    > On Sep 14, 2007, at 2:20 PM, Simon Kröger wrote:
    >
    >> Ruby Quiz wrote:
    >>> [...]
    >>>
    >>> $ time ruby ip_to_country.rb 68.97.89.187
    >>> US
    >>>
    >>> real 0m0.314s
    >>> user 0m0.259s
    >>> sys 0m0.053s

    >>
    >> Is an 'initialisation run' allowed to massage the data?
    >> (we should at least split the benchmarks to keep it fair)

    >
    > My script does need and initialization run, yes. I don't see any harm
    > in paying a one time penalty to set things up right.
    >
    >> Is it motivating or a spoiler to post timings?

    >
    > Motivating, definitely.
    >
    > James Edward Gray II


    Ok, my script does not need any initialization, it uses the file
    IpToCountry.csv exactly as downloaded.

    ----------------------------------------------------------------
    $ ruby -v
    ruby 1.8.4 (2005-12-24) [i386-cygwin]

    $ time ruby quiz139.rb 68.97.89.187
    US

    real 0m0.047s
    user 0m0.030s
    sys 0m0.030s

    $ time ruby quiz139.rb 84.191.4.10
    DE

    real 0m0.046s
    user 0m0.046s
    sys 0m0.015s
    ----------------------------------------------------------------

    This is on a Pentium M 2.13GHz Laptop with 2GB RAM and rather slow HD.

    cheers

    Simon

  5. Default Re: [QUIZ] IP to Country (#139)

    On Sep 14, 2007, at 2:35 PM, Simon Kr=F6ger wrote:

    > James Edward Gray II wrote:
    >> On Sep 14, 2007, at 2:20 PM, Simon Kr=F6ger wrote:
    >>
    >>> Ruby Quiz wrote:
    >>>> [...]
    >>>>
    >>>> $ time ruby ip_to_country.rb 68.97.89.187
    >>>> US
    >>>>
    >>>> real 0m0.314s
    >>>> user 0m0.259s
    >>>> sys 0m0.053s
    >>>
    >>> Is an 'initialisation run' allowed to massage the data?
    >>> (we should at least split the benchmarks to keep it fair)

    >>
    >> My script does need and initialization run, yes. I don't see any =20
    >> harm
    >> in paying a one time penalty to set things up right.
    >>
    >>> Is it motivating or a spoiler to post timings?

    >>
    >> Motivating, definitely.
    >>
    >> James Edward Gray II

    >
    > Ok, my script does not need any initialization, it uses the file
    > IpToCountry.csv exactly as downloaded.
    >
    > ----------------------------------------------------------------
    > $ ruby -v
    > ruby 1.8.4 (2005-12-24) [i386-cygwin]
    >
    > $ time ruby quiz139.rb 68.97.89.187
    > US
    >
    > real 0m0.047s
    > user 0m0.030s
    > sys 0m0.030s
    >
    > $ time ruby quiz139.rb 84.191.4.10
    > DE
    >
    > real 0m0.046s
    > user 0m0.046s
    > sys 0m0.015s
    > ----------------------------------------------------------------


    Wow, I'm impressed. Can't wait to see that code!

    James Edward Gray II=


  6. Default Re: [QUIZ] IP to Country (#139)

    > Wow, I'm impressed. Can't wait to see that code!

    Thanks.

    Because startup time startet to take over the benchmark:
    ----------------------------------------------------------------
    $ time ruby quiz139.rb 68.97.89.187 84.191.4.10 80.79.64.128 210.185.128.123
    202.10.4.222 192.189.119.1
    US
    DE
    RU
    JP
    AU
    EU

    real 0m0.078s
    user 0m0.046s
    sys 0m0.031s
    ----------------------------------------------------------------

    and by the way: thanks for telling me such a database exists!

    cheers

    Simon

  7. Default Re: [QUIZ] IP to Country (#139)

    I think that the timing of the scripts are not a good index. It all =20
    depends on what hardware/os you are running it on.
    If we want to use speed as an index we should probably have J.E. =20
    compare them all on the same machine.

    Maybe we could also write a ruby script that runs all the entry =20
    scripts and time them, and that could be another ruby quiz which will =20=

    also be voted on speed and then we could write a ruby script to time =20
    those entries an then we could .... Just ignore this paragraph

    Diego Scataglini

    On Sep 14, 2007, at 3:35 PM, Simon Kr=C3=B6ger <SimonKroeger@gmx.de> =
    wrote:

    > James Edward Gray II wrote:
    >> On Sep 14, 2007, at 2:20 PM, Simon Kr=C3=B6ger wrote:
    >>
    >>> Ruby Quiz wrote:
    >>>> [...]
    >>>>
    >>>> $ time ruby ip_to_country.rb 68.97.89.187
    >>>> US
    >>>>
    >>>> real 0m0.314s
    >>>> user 0m0.259s
    >>>> sys 0m0.053s
    >>>
    >>> Is an 'initialisation run' allowed to massage the data?
    >>> (we should at least split the benchmarks to keep it fair)

    >>
    >> My script does need and initialization run, yes. I don't see any =20
    >> harm
    >> in paying a one time penalty to set things up right.
    >>
    >>> Is it motivating or a spoiler to post timings?

    >>
    >> Motivating, definitely.
    >>
    >> James Edward Gray II

    >
    > Ok, my script does not need any initialization, it uses the file
    > IpToCountry.csv exactly as downloaded.
    >
    > ----------------------------------------------------------------
    > $ ruby -v
    > ruby 1.8.4 (2005-12-24) [i386-cygwin]
    >
    > $ time ruby quiz139.rb 68.97.89.187
    > US
    >
    > real 0m0.047s
    > user 0m0.030s
    > sys 0m0.030s
    >
    > $ time ruby quiz139.rb 84.191.4.10
    > DE
    >
    > real 0m0.046s
    > user 0m0.046s
    > sys 0m0.015s
    > ----------------------------------------------------------------
    >
    > This is on a Pentium M 2.13GHz Laptop with 2GB RAM and rather slow HD.
    >
    > cheers
    >
    > Simon
    >



  8. Default Re: [QUIZ] IP to Country (#139)

    On Sep 14, 2007, at 4:58 PM, diego scataglini wrote:

    > I think that the timing of the scripts are not a good index. It all
    > depends on what hardware/os you are running it on.
    > If we want to use speed as an index we should probably have J.E.
    > compare them all on the same machine.


    I view it that we are getting a rough idea of speeds, not exact
    counts. Both scripts timed so far seem to be able to answer the
    question in under a second on semi-current hardware. Good enough for
    me.

    > Maybe we could also write a ruby script that runs all the entry
    > scripts and time them, and that could be another ruby quiz which
    > will also be voted on speed and then we could write a ruby script
    > to time those entries an then we could .... Just ignore this paragraph


    Thank you for volunteering...

    James Edward Gray II


  9. Default Re: [QUIZ] IP to Country (#139)


    From: "Simon Kröger" <SimonKroeger@gmx.de>
    >
    > Ok, my script does not need any initialization, it uses the file
    > IpToCountry.csv exactly as downloaded.


    We probably did something similar. Mine also works on the
    unmodified IpToCountry.csv file.

    $ time ruby 139_ip_to_country.rb 67.19.248.74 70.87.101.66 205.234.109.18 217.146.186.221 62.75.166.87
    US
    US
    US
    GB
    DE

    real 0m0.122s
    user 0m0.015s
    sys 0m0.000s


    (ruby 1.8.4 (2005-12-24) [i386-mswin32], timed from cygwin bash shell,
    2GHz athlon64, winxp.)

    I don't think the timings are very accurate on this system. It
    didn't change much whether I looked up one IP or five.

    . . Looking up 80 IPs on one command line resulted in:

    real 0m0.242s
    user 0m0.015s
    sys 0m0.016s


    Regards,

    Bill



  10. Default Re: [QUIZ] IP to Country (#139)

    Ruby Quiz wrote:
    > This week's Ruby Quiz is to write a simple utility. Your program should accept
    > an IP address as a command-line argument and print out the two letter code for
    > the country that IP is assigned in.


    I assume that it's not ok for folk to use my Ruby GeoIP gem?
    It has a reasonable compromise between speed and memory usage.
    :-)

    Clifford Heath.

+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast

Similar Threads

  1. Re: [QUIZ] IP to Country (#139)
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 09-19-2007, 02:22 PM
  2. Re: [QUIZ] IP to Country (#139)
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 09-17-2007, 05:36 PM
  3. Fwd: [QUIZ] IP to Country (139)
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 09-16-2007, 10:27 AM
  4. Re: [QUIZ] IP to Country (#139)
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 09-16-2007, 08:20 AM
  5. Re: [QUIZ] IP to Country (#139)
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 09-14-2007, 07:11 PM