性能优化技巧 - 遍历

【摘要】
数据分析场景中,充斥着聚合运算,常见的有求和、计数、均值、最大最小值等等,想要得到正确的结果值,遍历技术必不可少,如何更加高效地对数据进行遍历?点击:性能优化技巧 - 遍历,来乾学院一探究竟!

 

1. 存储方案

集文件是行存方式,组表有行存和列存两种方式。两种格式都有一定压缩效果。

首先,我们来建立一个的普通的文本文件,并在该文件中生成一些数据,代码如下:

  A B
1 =file("txt/employee.txt")  
2 =file("info/ming_en_female.txt").import@i() =A2.len()
3 =file("info/ming_en_male.txt").import@i() =A3.len()
4 =file("info/xing_en.txt").import@i() =A4.len()
5 =city=file("info/city_en.txt").import@i() =A5.len()
6 =salary=20000 /10000~30000
7 =["one","two","three","four","five","six","seven","eight","nine","ten"] =A7.len()
8 =height=50 /160~210cm
9 =weight=50 /50~100kg
10 =birthtime=946656 /1970~2000
11 for 100 =to((A11-1)*100000+1,A11*100000).new(~:id,if(rand(2)==0,A2(rand(B2)+1),A3(rand(B3)+1))+" "+A4(rand(B4)+1):name,if(A2.pos(name.array(" ")(1)),"Female","Male"):sex,A5(rand(B5-1)+1):city,date(rand(birthtime)*long(1000000)):birthday,rand(salary)+10000:salary,A7(rand(B7-1)+1):level,rand(height)+160:height,rand(weight)+50:weight,if(rand(2)==0,A2(rand(B2)+1),A3(rand(B3)+1))+"&"+A4(rand(B4)+1)+"  Co. Ltd":company)
12   =A1.export@at(B11)

代码1.1

代码 1.1,生成一个 txt 文件,总记录数为 1000 万,其中部分数据如图 1.1 所示。

图1.1

 

  A
1 =file("txt/employee.txt").cursor@t()
2 =file("btx/employee.btx").export@ab(A1)

代码1.2

 

  A
1 =file("txt/employee.txt").cursor@t()
2 =file("ctx/employee.ctx").create(#id,name,sex,city,birthday,salary,level,height,weight,company).append(A1)

代码1.3

 

  A
1 =file("txt/employee.txt").cursor@t()
2 =file("ctx/[email protected]").create@r(#id,name,sex,city,birthday,salary,level,height,weight,company).append(A1)

代码1.4

代码 1.2、1.3、1.4 分别使用代码 1.1 建立的 txt 文件,转为集文件 employee.btx、列存组表文件employee.ctx和行存组表文件[email protected],各文件大小如图 1.2 所示。

 

图1.2

按照文件占用的硬盘空间大小排序可以得到:txt> 行存组表 > 集文件 > 列存组表。可见,同样的数据,在不同的文件存储格式下,所占用的硬盘空间大小也不同,而文件的大小又会直接影响遍历的效率。

 

排序能有效提高列存组表压缩效率,重复次数多的字段排到前面。

  A
1 =file("ctx/employee.ctx").create
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值