in reply to fast way to split and sum an input file
someone told me perl was extremely slow and it is wiser to use the shell.
Tell him he's an idiot and it's wiser to use the right tool for the right job (ok, leave that first part out if you want to be diplomatic).
...(They) wrote which ran in 3 secs in awk and c and 3 minutes in perl.
I used just a naive split in perl, and got about 25 seconds (perl) for processing 100,000 lines of 100 fields vs. about 10 seconds in awk. The perl took about 45 seconds if I used the "-a" and "-F" options instead of just using $tot += (split /,/)[99].
But what does that mean? For something insanely simple like this, I might use awk (and the 'C' just does not look insanely simple, so I don't think I'd do it that way). If I wanted to do something more complicated, like keeping group sums of combinations of other fields, and key it to some other nested data structures, and look up some other data in a database and some other data from the web, then it's wiser to get it done easily in your favorite scripting language.
FYI, the awk code (I have an old awk that only allows 99 fields):
#!/usr/bin/awk -f BEGIN { FS="," } { tot += $99 } END { print tot }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
This is my code
by broomberg2 (Initiate) on Aug 30, 2005 at 13:36 UTC |