Good work. It will be interesting to look at similar benchmarks of specific
operations:
* generating random data
* adding
* subtracting
* multiplying
* division
On 9/21/20 7:04 PM, 钟巍 wrote:
> Hi Vividsnow&g.vanuxemu&deforest,
> thanks for education me on PDL.
> I improve my benchmark with tips:
> 1. use vividsnow's template to only count on code which really caculated ,
> exclude import and etc..
> 2. use foreach n from (1..9) , (a,b,c)= ( 50,50,50) ; iterate (n*a,n*b,n*c)
> into PDL and numpy for + and /.
> 3, use constant 0/1 vector and random version
>
> so I share the chart with you. all run memory cost (max 4G ) under my memory
> limited ( I have 6G memory in my PC)
> X direction: a number ( 50...450), b,c use the same number of a. for example
> x=100 mean (a,b,c)= (100,100,100)
> Y direction: runtime with seconds
>
> I see the similar performance on small size of vector before ( 150*150*150),
> but numpy win when the size become bigger.
>
> weizhong@weizhong-VirtualBox:~/Git/compare-pdl_numpy$ ./compare2.csh
>
> ######################
>
> Python test2.py:
>
> i: 50 j: 50 k: 50
> n: 1 a: 50 b: 50 c: 50 use
> constant: 0.014253
> n: 2 a: 100 b: 100 c: 100 use
> constant: 0.125285
> n: 3 a: 150 b: 150 c: 150 use
> constant: 0.356969
> n: 4 a: 200 b: 200 c: 200 use
> constant: 0.587934
> n: 5 a: 250 b: 250 c: 250 use
> constant: 1.122064
> n: 6 a: 300 b: 300 c: 300 use
> constant: 1.811969
> n: 7 a: 350 b: 350 c: 350 use
> constant: 2.801928
> n: 8 a: 400 b: 400 c: 400 use
> constant: 4.199447
> n: 9 a: 450 b: 450 c: 450 use
> constant: 5.861006
> n: 1 a: 50 b: 50 c: 50 use random:
> 0.017121
> n: 2 a: 100 b: 100 c: 100 use random:
> 0.261941
> n: 3 a: 150 b: 150 c: 150 use random:
> 0.762444
> n: 4 a: 200 b: 200 c: 200 use random:
> 1.643807
> n: 5 a: 250 b: 250 c: 250 use random:
> 3.033077
> n: 6 a: 300 b: 300 c: 300 use random:
> 5.334194
> n: 7 a: 350 b: 350 c: 350 use random:
> 8.356894
> n: 8 a: 400 b: 400 c: 400 use random:
> 12.36961
> n: 9 a: 450 b: 450 c: 450 use random:
> 17.57204
> ######################
>
> Perl test2.pl:
>
> n 1 a: 50 b: 50 c: 50 use
> constant: 0.006611
> n 2 a: 100 b: 100 c: 100 use
> constant: 0.167906
> n 3 a: 150 b: 150 c: 150 use
> constant: 0.373352
> n 4 a: 200 b: 200 c: 200 use
> constant: 1.039262
> n 5 a: 250 b: 250 c: 250 use
> constant: 1.939946
> n 6 a: 300 b: 300 c: 300 use
> constant: 3.279632
> n 7 a: 350 b: 350 c: 350 use
> constant: 5.171424
> n 8 a: 400 b: 400 c: 400 use
> constant: 7.532095
> n 9 a: 450 b: 450 c: 450 use
> constant: 10.67638
> n 1 a: 50 b: 50 c: 50 use random:
> 0.110154
> n 2 a: 100 b: 100 c: 100 use random:
> 0.320554
> n 3 a: 150 b: 150 c: 150 use random:
> 0.733779
> n 4 a: 200 b: 200 c: 200 use random:
> 1.982923
> n 5 a: 250 b: 250 c: 250 use random:
> 3.925586
> n 6 a: 300 b: 300 c: 300 use random:
> 6.573884
> n 7 a: 350 b: 350 c: 350 use random:
> 10.32816
> n 8 a: 400 b: 400 c: 400 use random:
> 15.31966
> n 9 a: 450 b: 450 c: 450 use random:
> 22.99678
>
>
>
> *_test2.py:_*
> #!/home/weizhong/tools/Python-3.8.5/python
> import numpy as np
> repeat =10
> (i,j,k) = (50,50,50)
> print("i:",i,"j:",j,"k:",k)
>
> def test(a,b,c):
> """test function"""
> X = np.random.rand(a,b,c)
> Y = np.random.rand(a,b,c)
> Z1 = X+Y
> Z2 = X/Y
> def testConst(a,b,c):
> X = np.zeros((a,b,c))
> Y = np.ones((a,b,c))
> Z1 = X+Y
> Z2 = X/Y
>
>
>
> if __name__ == '__main__':
> import timeit
> for n in range(1,10,1):
> a=i*n
> b=j*n
> c=k*n
> print("n:",n,"a:",a,"b:",b,"c:",c," use
> constant:",timeit.timeit("testConst(a,b,c)", setup="from __main__ import
> test,testConst; ", number = repeat,globals=globals()))
> for n in range(1,10,1):
> a=i*n
> b=j*n
> c=k*n
> print("n:",n,"a:",a,"b:",b,"c:",c," use
> random:",timeit.timeit("test(a,b,c)", setup="from __main__ import
> test,testConst; ", number = repeat,globals=globals()))
>
> *_test2.pl_*
> #!/home/weizhong/tools/perl-5.32.0/perl
>
> use PDL;
> use Benchmark ':hireswallclock';
> use Time::HiRes qw( time);
> $PDL::BIGPDL = 1;
> my $repeat = 10;
> my ($i,$j,$k) = (50,50,50);
> #my ($a,$b,$c) = (100,50,50);
> #my $repeat = 10;
> #my ($a,$b,$c) = (500,500,500);
> foreach my $n (1..9){
> print "n ",$n," ";
> $a=$i*$n;
> $b=$j*$n;
> $c=$k*$n;
> print "a: ".$a." b: ".$b." c: ".$c." ";
> print "use constant: ";
> print timeit($repeat, sub {
> my $x = zeroes(double,$a,$b,$c);
> my $y = ones(double,$a,$b,$c);
> $z1 = $x + $y;
> $z2 = $x / $y;
> })->real, "\n";
> }
> foreach my $n (1..9){
> print "n ",$n," ";
> $a=$i*$n;
> $b=$j*$n;
> $c=$k*$n;
> print "a: ".$a." b: ".$b." c: ".$c." ";
> print "use random: ";
> print timeit($repeat, sub {
> my $x = random(double,$a,$b,$c);
> my $y = random(double,$a,$b,$c);
> $z1 = $x + $y;
> $z2 = $x / $y;
> })->real, "\n";
> }
>
> *_compare2.csh:_*
>
> #!/bin/csh -f
> echo "######################";
> echo "Python test2.py:";
> ./test2.py
> echo "######################";
> echo "Perl test2.pl:";
> ./test2.pl
> #echo "###################
>
> thanks!
> wei
>
>
>
>
> At 2020-09-21 19:38:23, "vividsnow" <[email protected]> wrote:
>>Try to exclude startup time:
>>
>># perl/pdl
>>
>>use PDL;
>>use Benchmark ':hireswallclock';
>>$PDL::BIGPDL = 1;
>>
>>print timeit(1000, sub {
>> my $x = random(double,100,50,50);
>> my $y = random(double,100,50,50);
>> $z1 = $x + $y;
>> $z2 = $x / $y;
>>})->real, "\n";
>>
>>
>># python3/numpy
>>
>>import numpy as np
>>
>>def test():
>> """test function"""
>> X = np.random.rand(100,50,50)
>> Y = np.random.rand(100,50,50)
>> Z1 = X+Y
>> Z2 = X/Y
>>
>>if __name__ == '__main__':
>> import timeit
>> print(timeit.timeit("test()", setup="from __main__ import test", number =
>> 1000))
>>
>>
>>On 9/20/20 5:11 PM, 钟巍 wrote:
>>> Hi all,
>>> I am new to PDL. I want to know where is PDL performance.
>>>
>>> I test on same virtial machine with lastest version of perl and python in
>>> Ubuntu 20.04 LTS
>>>
>>> Perl version:v5.32.0
>>> Python version:3.8.5
>>> I have a little disappoint about the result:
>>> Perl slower a lot than python.
>>>
>>> weizhong@weizhong-VirtualBox:~/Git/compare-pdl_numpy$ ./compare.csh
>>>
>>> Python test1.py:
>>> 0.5u 1.0s 0:01.84 88.0% 0+0k 0+0io 0pf+0w
>>>
>>> Perl test1.pl:
>>> 1.2u 2.0s 0:05.83 55.5% 0+0k 19064+0io 907pf+0w
>>>
>>> Python test1.py:
>>> 0.7u 0.7s 0:02.54 60.2% 0+0k 52008+0io 141pf+0w
>>>
>>> Perl test1.pl:
>>> 1.3u 1.9s 0:05.28 61.3% 0+0k 30432+0io 1005pf+0w
>>>
>>> Perl Code(test1.pl):
>>>
>>> #!/home/weizhong/tools/perl-5.32.0/perl use PDL; $PDL::BIGPDL = 1; $X =
>>> zeroes(1000,500,500); $Y = ones(1000,500,500);
>>> $Z1 = $X + $Y; $Z2 = $X / $Y;
>>> [download]
>>> <https://www.perlmonks.org/?abspart=1;displaytype=displaycode;part=1;node_id=11121959>
>>>
>>> Python Code(test1.py):
>>>
>>> #!/home/weizhong/tools/Python-3.8.5/python import numpy as np X =
>>> np.zeros((1000,500,500)) Y = np.ones((1000,500,500))
>>> Z1 = X+Y Z2 = X/Y
>>> [download]
>>> <https://www.perlmonks.org/?abspart=1;displaytype=displaycode;part=2;node_id=11121959>
>>>
>>> compare.csh:
>>>
>>> #!/bin/csh -f echo "Python test1.py:"; time ./test1.py echo "Perl
>>> test1.pl:"; time ./test1.pl echo "Python test1.py:";
>>> time ./test1.py echo "Perl test1.pl:"; time ./test1.pl
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> pdl-general mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>>>
>>
>>
>>_______________________________________________
>>pdl-general mailing list
>>[email protected]
>>https://lists.sourceforge.net/lists/listinfo/pdl-general
>
>
>
>
>
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general