Pascal script VS Paxcompiler4.2 终极测试
FastScript一直号称速度最快?Paxcompiler一直号称最快?到底哪个更稳定更快速?
今天我不拿fastscript跟paxcompiler来比,因为在实际应用中,用于基础服务框架中的脚本引擎部分,fastscript远还满足不了真正的RTTI-RPC需求,我们需要功能更全面,脚本编译能力更强,基础功能单元覆盖更广的脚本引擎。因此我拿多年一直在用的pascal script在64位多线程情况下跟paxcompiler测试一下究竟有多大差距?
编译环境:Delphi XE10.2.3,Target-platforms(64-bit Windows) - Release
Pascal script默认加载内置的全部plugins
线程数(100):
threads: 100
threads for Pascal script Plapsed time: 831.19ms (max-cpu: 4%)
Memory: 1.4M
threads: 100
threads for PaxCompiler4.2 Plapsed time: 1.79s
Memory: 158.4M
线程数(500):
threads: 500
threads for Pascal script Plapsed time: 2.77s(max-cpu: 29%)
Memory: 121M
threads: 500
threads for PaxCompiler4.2 Plapsed time: 8.52s(max-cpu: 51.5%)
Memory: 1391M
差距已经非常明显,最后再测一下1000线程的情况
线程数(1000)
threads: 1000
threads for Pascal script Plapsed time: 4.59s(max-cpu: 62.6%)
memory: 686.7M
threads: 1000
threads for PaxCompiler4.2 Plapsed time: 16.71s(max-cpu: 72.1%)
memory: 3432M
到这里似乎已经没有再往下测的必要了,结果已经出来:
线程数 | 部分性能参数 | Pascal script | Paxcompiler 4.2 | ||
100 | plapsed time | 831.19ms | 1.79s | ||
memory | 1.4M | 158.4M | |||
max-cpu | 4% | 21.90% | |||
500 | plapsed time | 2.77s | 8.52s | ||
memory | 121M | 1391M | |||
max-cpu | 29% | 51.50% | |||
1000 | plapsed time | 4.59s | 16.71s | ||
memory | 686.7M | 3432M | |||
max-cpu | 62.60% | 72.10% |
TestPS = class(TThread)
private
FTypes: TPSEngineTypeClass;
FMemo: TMemo;
procedure StartThread;
procedure Finished;
public
constructor Create(mem: TMemo; ATypes: TPSEngineTypeClass);
destructor Destroy; override;
procedure Execute; override;
end;
TestPax = class(TThread)
private
FTypes: TPSEngineTypeClass;
FMemo: TMemo;
procedure StartThread;
procedure Finished;
public
constructor Create(mem: TMemo; ATypes: TPSEngineTypeClass);
destructor Destroy; override;
procedure Execute; override;
end;
var
Form2: TForm2;
TotalThread: Integer;
ftim: TPrecisionTimer;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
i: Integer;
et: TPSEngineTypeClass;
begin
Memo1.Lines.Add('threads: ' + inttostr(SpinEdit1.Value));
TotalThread := 0;
et := [];
for I := 0 to CheckListBox1.Count-1 do
if CheckListBox1.Checked[i] then
include(et, TPSPluginType(i));
for i := 1 to SpinEdit1.Value do
begin
TestPS.Create(Memo1, et);
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
i: Integer;
et: tpsenginetypeclass;
begin
Memo1.Lines.Add('threads: ' + inttostr(SpinEdit1.Value));
TotalThread := 0;
et := [];
for I := 0 to CheckListBox1.Count-1 do
if CheckListBox1.Checked[i] then
include(et, TPSPluginType(i));
for i := 1 to SpinEdit1.Value do
begin
TestPax.Create(Memo1, et);
end;
end;
从结果来看,PS的500线程的性能几乎达到PAX 100线程的性能;PS1000的性能除了CPU占用稍高,运行时间,内存占用和CPU占用三项已经远超PAX500,在PS1000 VS PAX1000同等条件下,PAX1000的综合性能明显落后PS1000接近4倍,虽然本次测试仅在从脚本对象创建-编译-运行-释放完整模式下进行,PAX可通过LoadFrom方式加载预编译字节码数据来缩短重复编译的时间,PS同样可以通过在Compile完成之后GetOutput字节码,再通过LoadData加载的方式提高性能,因此,光内存占用一项,PAX4.2已经完败,开除出局,永不关注。
那么,PS在仅加载Classes和DB两个plugin的条件下(实际上,我大部分只用到这两块,后端处理不需要诸如Forms, Graphics,Dialogs,Controls之类的东东),500线程下仅为1.5s左右,500TPS目前满足我对单进程脚本引擎的能力要求,那就是它了。
至于什么TMS Scripter,FastScript等等 脚本引擎,我并没有多大兴趣继续去测,不说高压力测试下稳定运行,就是单线程下长时间运行不宕掉感觉都难,有点扯远了,这种东西,谁用谁知道,实践出真知,时间便是最好的测试工具。
此文仅记录个人测试结果备忘,如有不周,请海涵。