hash 归一统计

来源:互联网 发布:java 文件大小 编辑:程序博客网 时间:2024/06/10 03:29
 
#!/usr/bin/perl use strict;use POSIX qw(strftime);my  $srcfile=$ARGV[0];open LG, "<", $srcfile or die $!;my %hash=();   while (<LG>) {chomp;   chomp $_;  $hash{$_}=1;}close LG;print scalar(keys(%hash)) ;

功能和 sort -u srcfile|wc -l 一样

用300个文件,每个100万行数据测试。sort -u srcfile|wc -l 花了4个多小时,hash统计为25分钟左右。

速度相差10倍左右。所以数据量大的时候,最好还是自己写东西统计数据。