Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:PEL中等效代码行数,对执行速度影响很大

1楼
youop 发表于:2021/3/24 18:21:47
最近看到论坛里的显示执行时间的语句,一时来了兴趣,开始看PEL语言执行效率,发现刨去语句本身算法的难易程度,等效一行代码本身就对执行效率有很大影响,测试如下:

选取黄金连续合约2014年8月13~2021年3月22日,1分钟周期,大约是115w个Bar。
先使用最简单的双均线穿越模型,大约使用了3s不到。
2021-03-24 18:11:35.189    开始
2021-03-24 18:11:38.023    结束

而使用更为无效的重复赋值语句重复赋值50次 ,不含任何函数,大约使用了4s不到
2021-03-24 18:13:49.900    Sta
2021-03-24 18:13:54.094    End

使用更为无效的重复赋值语句重复赋值100次 ,不含任何函数,大约使用了7.5s不到
2021-03-24 18:16:02.078    Sta
2021-03-24 18:16:09.612    End

所以这里没讨论计算的复杂程度,在PEL语言里,100句等效代码也不算多,光一行最简单的代码都能使代码效率有所降低,而在逐K+最后一根的模式下,接受1个tick不会所有刷新,但是等这个1分钟bar生成了,就要所有数据再次遍历一遍。
所以减少代码行数,或者把代码放入IF里面,的确很有必要。

附带最简单双均线系统:
if barpos = 1 then
 DEBUGFILE2('D:\2222.TXT','开始',0,1);

if barpos= DATACOUNT then
 DEBUGFILE2('D:\2222.TXT','结束',0,1);

www:=(c+o+h+l)/4;
ma1:=ma(www,500);
ma2:=ma(www,3000);

Kd:=cross(ma1,ma2);
Kk:=cross(ma2,ma1);

If kk and holding>0  Then
Begin
Sell(1,100%,Limitr,c-Mindiff);
End

If kd and holding<0 Then
Begin
Sellshort(1,100%,Limitr,c+Mindiff);
End


If Kd And holding=0 Then
Begin
Buy(1,1,Limitr,c+Mindiff);
End

If Kk And holding=0 Then
Begin
Buyshort(1,1,Limitr,c-Mindiff);
End


无意义系统代码:
if barpos = 1 then
 DEBUGFILE2('D:\执行时间.txt','Sta',0,1);

if barpos= DATACOUNT then
 DEBUGFILE2('D:\执行时间.txt','End',0,1);


//一行10个X
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;X:=888;
[此贴子已经被作者于2021/3/24 18:23:00编辑过]
2楼
youop 发表于:2021/3/24 19:39:00
使用全局变量语句重复赋值100次 ,不含任何函数,大约使用了6s不到
2021-03-24 19:37:20.892    Sta
2021-03-24 19:37:26.218    End

全局变量代码:
if barpos = 1 then
 DEBUGFILE2('D:\执行时间.txt','Sta',0,1);

if barpos= DATACOUNT then
 DEBUGFILE2('D:\执行时间.txt','End',0,1);

VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;VARIABLE:x1:=0;
3楼
youop 发表于:2021/3/24 19:42:20
使用全局变量50个,大约是3s
2021-03-24 19:39:45.020    Sta
2021-03-24 19:39:48.026    End

所以在计算量大差不差的情况下,代码行数和执行时间大概是成一次函数关系 ,正相关
共3 条记录, 每页显示 10 条, 页签: [1]


Powered By Dvbbs Version 8.3.0
Processed in .10156 s, 2 queries.