From: William James Date: 2005-02-09T18:15:06+09:00 Subject: Re: Benchmark Mono - Ruby Glenn Parker wrote: > .... In general, > Perl and Python do not do nearly so poorly in such comparisons. I was surprised to discover that Ruby was slower at parsing a certain csv file than Brian Kernighan's version of Awk was. The file contains 26907 copies of 3.1415926535,1492,"Hello, worldly ones!",foo bar,"Just ""peachy"" keen" A different file that had lines composed of many fields of 1 character was parsed at the same speed by both languages. * # For the 26907 records in standard-data-big, * # takes about 4.3 seconds. Faster than Ruby, * # which takes about 6.7 seconds (5.9 in fast mode). * * { * # print * parse_csv( $0, rec ) * # printf "[" * # sep = "" * # for (i=1;i in rec; i++) * # { printf "%s<%s>", sep, rec[i] * # sep = ", " * # } * # print "]" * } * END { print NR } * * function parse_csv( str, array, field,i ) * { split( "", array ) * str = str "," * while ( match(str, * /[ \t]*("[^"]*(""[^"]*)*"|[^,]*)[ \t]*,/) ) * { field = substr( str, 1, RLENGTH ) * gsub( /^[ \t]*"?|"?[ \t]*,$/, "", field ) * gsub( /""/, "\"", field ) * array[++i] = field * str = substr( str, RLENGTH + 1 ) * } * }