It's been a while since there was a golf, so I thought I would post a hole.

Running tcpdump on a *nix box will give you the output something akin to:

23:02:57.121780 receiveServer.yourDomain.com.ssh > targetServer.yourDo +main.com.1060: P 2193476388:2193476432(44) ack 3461777800 win 16060 ( +DF) [tos 0x10] 23:02:57.121937 targetServer.yourDomain.com.1060 > receiveServer.yourD +omain.com.ssh: . ack 44 win 16328 (DF) 23:02:57.123952 receiveServer.yourDomain.com.2113 > dns.yourDomain.com +.domain: 56467+ (45) 23:02:57.124389 dns.yourDomain.com.domain > receiveServer.yourDomain.c +om.2113: 56467* 1/3/3 (189) 23:02:57.124931 receiveServer.yourDomain.com.2113 > dns.yourDomain.com +.domain: 56468+ (44) 23:02:57.125371 dns.yourDomain.com.domain > receiveServer.yourDomain.c +om.2113: 56468* 1/3/3 (189) 23:02:57.125953 receiveServer.yourDomain.com.ssh > targetServer.yourDo +main.com.1060: P 44:336(292) ack 1 win 16060 (DF) [tos 0x10] 23:02:57.126299 receiveServer.yourDomain.com.2113 > dns.yourDomain.com +.domain: 56469+ (41) 23:02:57.126818 dns.yourDomain.com.domain > receiveServer.yourDomain.c +om.2113: 56469* 1/4/4 (209) 23:02:57.127455 receiveServer.yourDomain.com.ssh > targetServer.yourDo +main.com.1060: P 336:628(292) ack 1 win 16060 (DF) [tos 0x10]
Just recently, I helped a person who's assignment for a class was to analyze this output and deduce how long it took to load a site. That is, you took the last time stamp and subtracted the first time stamp from it (this was done while connecting via http to a website).

So, I helped the person do it in Perl; then for my own amusement, I golfed it. You can assume (as I did) that the hours and minutes would stay the same lest you run into crazy time to integer conversion issues. Running it against the output posted above should give you .00567.

Here's what I came up with:

Stroke #1:
123456789 2 3 4 + 5 6 % cat data.output | perl -ne'undef$/;/.{6}(.{9}).*[\d|:]{6}([\d|\.]{9} +)(?!\n)/s,print$2-$1'

Stroke #2:
123456789 2 3 4 + 5 6 % cat data.output | perl -n0e'/.{6}(.{9}).*[\d|:]{6}([\d|\.]{9})(?!\n) +/s,print$2-$1.'

Happy Golfin',
Jeremy

P.S. This is my first golf.


In reply to (Golf) Analyzing Time From tcpdump Output by enoch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.