hi there Serdar Yegulalp here for Infoworld at IDG. Today in Smart Python i'm going to take a
look at piston an alternate python runtime still in its early stages that's intended to speed up
execution of python programs without having to make changes to them now first a little history
piston first appeared as a project at dropbox where python was in significant use and where
the engineers wanted to see how much they could accelerate python workloads by way of using just
in time compilation also known as jitting this is the same technique that the pi pi runtime
also uses and i've linked to my earlier video below about pi pi but piston is functionally
different first off it uses python's original code base instead of being a complete rewrite and
second it uses different acceleration techniques and because python hues closely to the original
python runtime you can run the vast majority of python code and libraries as is what i'm going
to do here is run a few benchmark scripts in each of the three runtimes i've been talking about the
stock c python runtime pi pi and piston because piston right now only runs on ubuntu i've set up
an ubuntu vm with four virtual cores to run tests for all three so that it makes a fair comparison
actually the first thing i want to show is not a benchmark but the base startup times
for each of the run times this is important because if you have a script that only runs
a short while and then exits the startup time for the runtime is going to be an issue
as you can see here see python loads very quickly and since piston is based
on c python's own codebase it also starts up quite snappily but pi pi has a very long
startup time so its optimal use case is for long-running applications like servers now
for the benchmarks the first benchmark is simple math which is one of python's biggest weaknesses
python makes no assumptions about what any one particular object is when you run a script with
it and so constant checking slows down operations and tight loops like this math benchmark
each time a name or an object has to be resolved python does it from scratch every single time
one of the optimizations that jit could make is to create an optimized version of a given function
based on what kind of parameters it receives or some other conditions so things like math
operations and tight loops can speed up the number we're getting here by the way is the lowest of
three averages across 10 runs repeated 10 times now if we run the same test with pi pi we're going
to get something like a 10-fold increase in speed this is extremely impressive given that we don't
have to actually do anything to the script all we have to do is drop in the pi pi runtime and we get
an instant speed up that's been pi pi's selling point for quite some time and it's also one of
the intended uh advantages of running using piston however the disadvantage with pipe is that again
it takes a lot longer to get started with piston there is not as much of a speed up over c python
it's about 20 by my by my own calculations it's not nearly as dramatic as using pi pi but the
piston runtime launches about as quickly as c python itself so it's ideally much more suited
to speeding up shorter running applications i have another benchmark here that i've used previously
in earlier videos called the google engram benchmark this runs single threaded and it
paused through a data set of about 187 megabytes a csv file and then generates some summary
statistics from it when i run this in c python it generally takes about 20 to 23 seconds to run
now i can speed this up and see python by running it multi-threaded there's another version of the
script which will be able to use multi-processing actually to divide up the workload and that does
improve the performance considerably however for the sake of this test i've decided to use
the single the single threaded version to make the differences a little more dramatic or in this case
not so dramatic because when we run c python's version it takes about 20 seconds like i said
but pi pi's version is not really very much of an improvement it's only about 18 or 19 seconds
and when we run the same workload with piston we get about the same improvement as with pi pi
and a big part of this is because this particular workload is highly dependent on disk io whenever
you have a workload that is dependent on some external circumstances like the network or like
the disk basically anything that instruction optimization is not going to be able to touch
you're not going to see a tremendous improvement so this is something you need to consider whenever
you're looking at alternate runtimes there's a chance that whatever use case you're coming up
with there may not be much of an improvement simply because the use case cannot be improved
with an alternate runtime it'll only be improved for instance by faster disk hardware or some
network caching or some other modification to the actual workload itself so you do have to keep
this in mind so to sum up with regard to piston though this is still very much an early project
so any of the performance gains that i've seen with it so far are still relatively small compared
to more developed projects like pi pi but the fact that they're starting by using the original c
python code base is quite promising because it means that there will be far fewer compatibility
issues along the way and there's also a chance although i would not say the biggest of ones
that any of the changes made to piston could eventually be contributed back to the main c
python runtime in some form and thus speeding up c python for everybody that's it for this video
if you liked it please leave a comment below don't forget to subscribe to the idg tech talk
channel on youtube and for more python tips be sure to follow us on facebook youtube and
infoworld.com you