Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Edit2. Here's PDL vs. numpy simple performance test in earnest, I hope Python code really does what I intended, and so no more blunders. I don't see any "numpy is better than PDL" as claimed, except PDL devs didn't bother to optimize "zeroes", as, it looks, it really fills every 8 bytes, cell by cell by cell... Too bad if initializing lots of arrays with zeroes is mission-critical. (That said, of course PDL isn't perfect.) Python3 and numpy are from 18.04LTS repositories.

import time import numpy as np d = (1000,500,500) t = time.time(); x = np.zeros(( d )); print( time.time() - t ) t = time.time(); y = np.ones(( d )); print( time.time() - t ) t = time.time(); z = x / y; print( time.time() - t ) 1.1920928955078125e-05 0.6920394897460938 1.205686330795288 use strict; use warnings; use feature 'say'; use Time::HiRes 'time'; use PDL; $PDL::BIGPDL = $PDL::BIGPDL = 1; my @d = (1000,500,500); my $t; $t = time; my $x = zeroes( @d ); say time - $t; $t = time; my $y = ones( @d ); say time - $t; $t = time; my $z = $x / $y; say time - $t; 0.727283954620361 0.730240821838379 0.971168994903564


Edit. I was wrong about 'float32' being default for numpy, sorry. My answer doesn't explain the observed speed comparison.


As quick googling shows, default data type for numpy is 32-bit "single precision" "float". PDL default is 64-bit "double precision" "double". Hence illusory 2x speed difference. Your example is just trivial allocation/arithmetic in underlying C, after all. In PDL, you can specify data type in constructor, as e.g. typing "?zeroes" in interactive shell will explain (and as shown below).

Complete cmd.exe window dump to show versions, etc.:

---------------------------------------------- Welcome to Strawberry Perl PDL Edition! * URL - + * to launch perl script run: perl c:\my\scripts\ * to start PDL console run: pdl2 * to update PDL run: cpanm PDL * to install extra module run: cpanm PDL::Any::Module or if previous fails: ppm PDL::Any::Module * or you can use dev tools like: gcc, g++, gfortran, gmake * see README.TXT for more info ---------------------------------------------- Perl executable: C:\berrybrew\strawberry-perl-\perl\ +bin\perl.exe Perl version : 5.30.1 / MSWin32-x64-multi-thread PDL version : 2.019 C:\berrybrew\strawberry-perl->pdl2 Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call + didn't work. The COLUMNS and LINES environment variables didn't work +. at C:/berrybrew/strawberry-perl- +Term/ReadLine/ line 410. load_rcfile: got $HOME = C:\berrybrew\strawberry-perl- +DL\data load_rcfile: loading PDL/default.pdl Perldl2 Shell v0.008 PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file 'COPYING' in the PDL distribution. This is free software and you are welcome to redistribute it under certain conditions, see the same file for details. Loaded plugins: CleanErrors Commands Completion CompletionDriver::INC CompletionDriver::Keywords CompletionDriver::LexEnv CompletionDriver::Methods DDS FindVariable History LexEnv MultiLine::PPI NiceSlice PDLCommands Packages PrintControl ReadLineHistory Type 'help' for online help Type Ctrl-D or quit to exit Loaded PDL v2.019 pdl> pdl> $PDL::BIGPDL = 1 pdl> use Time::HiRes 'time'; *t = \&time pdl> @d=(500,500,500) # 8 GB RAM here, let's avoid swapping pdl> pdl> $t=t; $x=zeroes@d; $y=ones@d; $z=$x+$y; $z2=$x/$y; p t-$t 1.2526330947876 pdl> $t=t; $x=zeroes@d; $y=ones@d; $z=$x+$y; $z2=$x/$y; p t-$t 1.69825196266174 pdl> $t=t; $x=zeroes@d; $y=ones@d; $z=$x+$y; $z2=$x/$y; p t-$t 1.59618711471558 pdl> p $z2->info PDL: Double D [500,500,500] pdl> pdl> $t=t; $x=zeroes double,@d; $y=ones double,@d; $z=$x+$y; $z2=$x/$y +; p t-$t 1.64064288139343 pdl> $t=t; $x=zeroes double,@d; $y=ones double,@d; $z=$x+$y; $z2=$x/$y +; p t-$t 1.6656858921051 pdl> $t=t; $x=zeroes double,@d; $y=ones double,@d; $z=$x+$y; $z2=$x/$y +; p t-$t 1.68068408966064 pdl> pdl> $t=t; $x=zeroes float,@d; $y=ones float,@d; $z=$x+$y; $z2=$x/$y; +p t-$t 1.11372804641724 pdl> $t=t; $x=zeroes float,@d; $y=ones float,@d; $z=$x+$y; $z2=$x/$y; +p t-$t 0.841649055480957 pdl> $t=t; $x=zeroes float,@d; $y=ones float,@d; $z=$x+$y; $z2=$x/$y; +p t-$t 0.83014702796936 pdl> p $z2->info PDL: Float D [500,500,500] pdl>

In reply to Re: Perl PDL slower than python numpy (Updated2) by vr
in thread Perl PDL slower than python numpy by fanasy

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-05-21 17:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found