in reply to Camel vs. Gopher
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Camel vs. Gopher
by stevieb (Canon) on Dec 08, 2018 at 22:49 UTC | |
by kschwab (Vicar) on Dec 08, 2018 at 22:57 UTC |