-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perl Script (possible) Improvement #1
Comments
Thanks, I'll try it out later today and let you know. Good point, I've -steve On Fri, Feb 17, 2012 at 1:30 PM, Stevan Little <
|
hey, slight difference after repeated tests. i dont understand it, but it's there. https://github.com/lorca/flat_file_benchmark/blob/master/pics/benchmark.png |
Yes, that makes sense. I didn't expect anything huge. I suspect you might be able to get some more performance if you use the map operator too. my @rows = map { [ split /\t/ ] } <>; On Feb 18, 2012, at 4:57 PM, [email protected] wrote:
|
doesn't make sense to me but glad it makes sense to you :) it looks like they are both the same but my perl version has to do cool, i'll try out your new version, and let you know. -steve On Sat, Feb 18, 2012 at 4:11 PM, Stevan Little <
|
Actually it is fairly simple, but requires a bit of understanding of what the perl interpreter is doing under the hood. When you use the block form of a statement in Perl, like this ...
the interpreter has to create a lexical pad, which is the C-level data structure that the perl interpreter uses to store any variables created or used within the block. However, when you do a statement modifier version, like this …
the interpreter doesn't need to create a new lexical pad, which means less memory allocation and less CPU time. You can see this directly by dumping the optree that the perl interpreter creates.
You can see that the optrees are almost identical here with the exception of the So the third version I suggested, with the
As you can see it is smaller, but also if you look at line 7, the mapwhile/mapstart opcode, you can see that Perl has specialize opcodes for this particular idiom. This is where the Perl idea of TIMTOWTDI (There Is More Then One Way To Do It) can come in really handy. You can make tradeoffs and/or reap benefits based on your needs simply by doing it another way. |
Hmmm, you know, it is also possible that the |
yea, I just ran it. it uses a lot of memory, started swapping, then the On Sun, Feb 19, 2012 at 6:56 AM, Stevan Little <
|
Yeah, okay that makes sense too. Oh well, at least the statement modifier one is quicker. I am sure we could golf this down and squeak out even more performance, but it would be at the expense of readability which is not worth it. |
You may get some speed/memory improvements by turning the
while
statement in Perl into a statement modifier.With this change, Perl should not have to create a new lexical scope for the
while
block, which should save on memory and speed. Note that I haven't benchmarked this (my internet connection is not good enough at the moment to pull your full repo, TSVs and all) and it is entirely possible that it won't be significant enough to matter either.The text was updated successfully, but these errors were encountered: