Well, if you need it fast, this seems faster than golang:

$ # note, run it once before timing it...inline::c will cache the created code
$ time perl x.pl
0       999837
1       999643
2       998992
3       999381
4       1000629
5       999501
6       999830
7       1001287
8       1001751
9       999149

real    0m0.129s
user    0m0.124s
sys     0m0.004s

I'm "cheating" though:

#!/usr/bin/perl use Inline C; use strict; use warnings; my $count=doit(10_000_000); for my $int ( sort keys %{$count} ) { printf "%s\t%s\n", $int,$$count{$int}; } __END__ __C__ #include <string.h> SV* doit(int howmany) { HV* hv=newHV(); unsigned int count[10]={0}; time_t t; char key[2]; srand((unsigned) time(&t)); for (int i=0;i<howmany;i++) { count[rand()%10]++; } for (int i=0;i < 10;i++) { sprintf(key,"%d",i); hv_store(hv,key,1,newSVuv(count[i]),0); } return newRV_noinc((SV *)hv); }

In reply to Re: Camel vs. Gopher by kschwab
in thread Camel vs. Gopher by reisinge

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.