<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stefan-Marr.de &#187; Benchmarks</title>
	<atom:link href="http://soft.vub.ac.be/~smarr/tag/benchmarks/feed/" rel="self" type="application/rss+xml" />
	<link>http://soft.vub.ac.be/~smarr</link>
	<description>personal and research notes</description>
	<lastBuildDate>Tue, 24 Jan 2012 18:41:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Using R to Understand Benchmarking Results</title>
		<link>http://soft.vub.ac.be/~smarr/2011/09/using-r-to-understand-benchmarking-results/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-r-to-understand-benchmarking-results</link>
		<comments>http://soft.vub.ac.be/~smarr/2011/09/using-r-to-understand-benchmarking-results/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 11:15:18 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[RoarVM]]></category>
		<category><![CDATA[Smalltalk]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Virtual Machines]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://soft.vub.ac.be/~smarr/?p=441</guid>
		<description><![CDATA[Why R? Evaluating benchmark results with Excel became too cumbersome and error prone for me so that I needed an alternative. Especially, reevaluating new data for the same experiments was a hassle. However, the biggest problem with Excel was that I did not know a good way to query the raw data sets and group [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript" src="http://soft.vub.ac.be/~smarr/renaissance/code/shCore.js"></script>
<script type="text/javascript" src="http://soft.vub.ac.be/~smarr/renaissance/code/shBrushR.js"></script>
<link type="text/css" rel="stylesheet" href="http://soft.vub.ac.be/~smarr/renaissance/code/shCoreDefault.css"/>

<h2>Why R?</h2>

<p>Evaluating benchmark results with Excel became
   too cumbersome and error prone for me so that I needed an alternative.
   Especially, reevaluating new data for the same experiments was a hassle.
   However, the biggest problem with Excel was that I did not know a good
   way to query the raw data sets and group results easily to
   be able to answer different kind of questions about the data.
   Thus, I decided I need to learn how to do it in a better way.
   Since, I was not really happy with the debuggability, traceability,
   and reusability of my spreadsheets either, I gave up on Excel entirely.
   I bet, Excel can do most of the things I need, but I wanted a text-based
   solution for which I can use my normal tools, too.</p>

<p>While working on <a href="https://github.com/smarr/ReBench">ReBench</a>,
   I got already in touch with
   <a href="http://matplotlib.sourceforge.net/">matplotlib</a> to generate
   simple graphs from benchmark results automatically.
   But well, Python does not feel like the ultimate language for what I was
   looking for either. Instead, <a href="http://www.r-project.org/">R</a> was
   mentioned from time to time when it came to statistical evaluation of
   measurements. And, at least for me, it turned out to be an interesting
   language with an enormous amount of libraries. Actually, a bit
   to enormous for my little needs, but it looked like a good starting
   point to brush up on my statistics knowledge.</p>

<p>By now, I use it regularly and applied it to a number of problems,
   including my work on the <a href="https://github.com/smarr/RoarVM">RoarVM</a>
   and a paper about
   <a href="http://www.hpi.uni-potsdam.de/hirschfeld/projects/som/index.html#csompl">CSOM/PL</a>.</p>
   
<h2>Benchmark Execution</h2>

<p>Before we can analyze any benchmark results, we need a reliable way to
   execute them, ideally, as reproducible as possible. For that purpose,
   I use a couple of tools:</p>
   <dl>
     <dt><a href="https://github.com/smarr/ReBench">ReBench</a></dt>
     <dd>A Python application that executes benchmarks based on a given
         configuration file that defines the variables to be varied,
         the executables to be used and the benchmarks and their
         parameters.</dd>
     <dt><a href="http://www.squeaksource.com/SMark.html">SMark</a></dt>
     <dd>A Smalltalk benchmarking framework that allows one to write
         benchmarks in a style similar to how unit-tests are written.</dd>
     <dt><a href="https://github.com/tobami/codespeed">Codespeed</a></dt>
     <dd>This is mostly for the bigger picture, a web application
         that provides the basic functionality to track long-term
         performance of an application.<br/><br/></dd>
  </dl>

<p>Beside having good tools, serious benchmarking requires some background
   knowledge. Today&#8217;s computer systems are just to complex to get good
   results with the most naive approaches.
   In that regard, I highly suggest to read the following two
   papers which discussing many of the pitfalls that one encounters when
   working with modern virtual machines, but also just on any modern
   operating system and with state-of-the-art processor tricks.</p>
   
   <ul>
     <li><em>Georges, A.; Buytaert, D. &#038; Eeckhout, L.</em><br/>
         <a href="http://dx.doi.org/10.1145/1297105.1297033">Statistically Rigorous Java Performance Evaluation</a><br/>
         SIGPLAN Not., ACM, 2007, 42, 57-76. (<a href="http://itkovian.net/base/files/papers/oopsla2007-georges-preprint.pdf">PDF</a>)</li>
     <li><em>Blackburn, S. M.; McKinley, K. S.; Garner, R.; Hoffmann, C.; Khan, A. M.; Bentzur, R.; Diwan, A.; Feinberg, D.; Frampton, D.; Guyer, S. Z.; Hirzel, M.; Hosking, A.; Jump, M.; Lee, H.; Moss, J. E. B.; Phansalkar, A.; Stefanovik, D.; VanDrunen, T.; von Dincklage, D. &#038; Wiedermann, B.</em></li>
         <a href="http://dx.doi.org/10.1145/1378704.1378723">Wake Up and Smell the Coffee: Evaluation Methodology for the 21st Century</a>
         Commun. ACM, ACM, 2008, 51, 83-89. (<a href="http://domino.watson.ibm.com/comm/research_people.nsf/pages/hirzel.index.html/$FILE/cacm08-dacapo-benchmarks.pdf">PDF</a>)</li>
   </ul>
   

<h2>Getting Started with R</h2>

<p>Now, we need to find the right tools to get started with R.
   After searching a bit, I quickly settled on
   <a href="http://www.rstudio.org/">RStudio</a>. It feels pretty much like
   a typical IDE with a <a href="http://en.wikipedia.org/wiki/Read-eval-print_loop">REPL</a>
   at its heart. As you can see in the screenshot
   below, there are four important areas. Top-left are your *.R files
   in a code editor with syntax highlighting and code completion. Top-right
   is your current R workspace with all defined variables and functions.
   This allows also to view and explore your current data set easily.
   On the bottom-right, we got a window that usually contains either
   help texts, or plots.
   Last but not least, in the bottom-left corner is the actual REPL.</p>

<p><a href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/RStudio.png"><img
class="aligncenter size-medium wp-image-444" title="Screenshot of RStudio"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/RStudio-300x187.png"
alt="Screenshot of RStudio" width="300" height="187" /></a></p>

<p><code>Rscript</code> is the interpreter that can be used on the command-line
   and thus, is nice to have for automating tasks. I installed it using MacPorts.</p>

<p>This introduction is accompanied by a
   <a href="https://github.com/smarr/BenchR/blob/master/using-R-to-understand-benchmarking-results.R">script</a>.
   It contains all the code discussed here and can be used to follow the
   introduction avoiding to much copy&#8217;n'past. Furthermore, the code here
   is not as complete as the script, to be a little more concise.</p>

<p>The first thing to do after setting up R is to install some libraries.
   This can be done easily from the REPL by executing the following code:
   <code>install.packages("plyr")</code>. This will
   install the <code>plyr</code> library providing <code>ddply()</code>,
   which we are going to use later to process our data set.
   Before it is going to install the code, it will ask for a mirror nearby
   to download the necessary files.
   To visualize the benchmark results afterwards, we are going to use bean plots
   from the <code>beanplot</code> library. The <code>doBy</code> library
   provides some convenience functions from which we are going to use
   <code>orderBy()</code>.
   After the installing all libraries, they can be loaded by executing
   <code>library(lib_name)</code>.</p>

<p>The documentation for functions, libraries, and other topics is always
   just a question mark away. For instance, to find out how libraries are installed,
   execute the following code in the REPL: <code>?install.packages</code>.

<h2>Preprocessing Benchmark Results</h2>

<p>To give a little context, the experiment this introduction is based on
   tries to evaluate the impact of using an object table instead of direct
   references on the performance of our manycore Smalltalk, the RoarVM.</p>

<p>The data set is available here:
   <a href="http://stefan-marr.de/downloads/object-table-data.csv.bz2">object-table-data.csv.bz2</a>.
   Download it together with the <a href="https://raw.github.com/smarr/BenchR/master/using-R-to-understand-benchmarking-results.R">script</a> and
   put it into the same folder.
   After opening the script in RStudio, you can follow the description here
   while using the code in RStudio directly. The run-button will execute a
   line or selection directly in the REPL.</p>

<h3>Loading Data</h3>

<p>First, change the working directory of R to the directory where you put
   the data file: <code>setwd("folder/with/data-file.csv.bz2/")</code>.
   The file is a compressed comma-separated values file that contains
   benchmark results, but no header line. Furthermore, some of the rows do not
   contain data for all columns, but this is not relevant here and we can just
   fill the gabs automatically.
   Load the compressed data directly into R&#8217;s workspace by
   evaluating the following code:</p>
   
<pre class="brush: r; toolbar: false;">
bench &lt;- read.table("object-table-data.csv.bz2",
                    sep="\t", header=FALSE,
                    col.names=c("Time", "Benchmark", "VirtualMachine",
                                "Platform", "ExtraArguments", "Cores",
                                "Iterations", "None", "Criterion",
                                "Criterion-total"),
                    fill=TRUE)
</pre>

<p>As you can see in the workspace on the right, the variable <code>bench</code>
   contains now 60432 observations for 10 variables. Type the following
   into the REPL to get an idea of what kind of data we are looking at:
   <code>summary(bench)</code>, or <code>View(bench)</code>.
   Just typing <code>bench</code> into the REPL will print the plain content,
   too.
   As you will see, every row represents one measurement with a set of
   properties, like the executed benchmark, its parameters, and the virtual 
   machine used.
</p>

<h3>Transforming Raw Data</h3>

<p> As a first step, we will do some parsing and rearrange the data to
    be able to work with it more easily. The name of the virtual machine binary
    encodes a number of properties that we want to be able to access directly.
    Thus, we split up that information into separate columns. </p>

<pre class="brush: r; toolbar: false;">
bench &lt;- ddply(bench,
               ~ VirtualMachine, # this formula groups the data by the value in VirtualMachine
               transform,
               # the second part of the VM name indicates whether it uses the object table
               ObjectTable = strsplit(as.character(VirtualMachine), "-")[[1]][2] == "OT",
               # the third part indicates the format of the object header
               Header = factor(strsplit(as.character(VirtualMachine), "-")[[1]][3]))  
</pre>

<p> This operation could use some more explanation, but most important
    know now is that we add the two new columns and that the data
    is being processed grouped by the values in the <code>VirtualMachine</code>
    column. </p>

<p> The data set contains also results from another experiment and some of the
    benchmarks include very detailed information. Neither of those information
    is required at the moment and we can drop the irrelevant data points
    by using <code>subset</code>. </p>

<pre class="brush: r; toolbar: false;">
bench &lt;- subset(bench,
                Header == "full"         # concentrate on the VM with full object headers
                 &#038; Criterion == "total", # use only total values of a measurement
                select=c(Time, Platform, # use only a limited number of columns
                         ObjectTable, Benchmark, ExtraArguments, Cores))
</pre>

<p> Furthermore, we assume that all variations in measurements come from the
    same non-deterministic influences. This allows to order the measurements,
    before correlating them pair-wise. The data is order based on all columns,
    where <code>Time</code> is used as the first ordering criterion. </p>

<pre class="brush: r; toolbar: false;">
bench &lt;- orderBy(~Time + Platform + ObjectTable + Benchmark + ExtraArguments + Cores, bench)
</pre>

<h3>Normalizing Data</h3>

<p> In the next step, we can calculate the speed ratio between pairs of
    measurements. To that end, we group the data based the unrelated variables
    and divide the measured runtime by the corresponding measurement of the VM
    that uses an object table. Afterwards we drop the measurements for the VM
    with an object table, since the speed ratio here is obviously always 1.
</p>

<pre class="brush: r; toolbar: false;">
norm_bench &lt;- ddply(bench, ~ Platform + Benchmark + ExtraArguments + Cores,
                    transform,
                    SpeedRatio = Time / Time[ObjectTable == TRUE])
norm_bench &lt;- subset(norm_bench, ObjectTable == FALSE, c(SpeedRatio, Platform, Benchmark, ExtraArguments, Cores))
</pre>

<h2>Analyzing the Data</h2>

<h3>The Basics</h3>

<p> Now we are at a point were we can start to make sense of the benchmark
    results.
    The summary function provides now a useful overview of the data and
    we can for instance concentrate on the speed ratio alone.
    As you might expect, you can also get properties like the standard
    deviation, arithmetic mean, and the median easily: </p>

<pre class="brush: r; toolbar: false;">
summary(norm_bench$SpeedRatio)
sd(norm_bench$SpeedRatio)
mean(norm_bench$SpeedRatio)
median(norm_bench$SpeedRatio)
</pre>

<p> However, that is very simple, a bit more interesting are R&#8217;s features
    to query and process the data. The first question we are interested
    in is, whether there is actually an impact on the performance difference
    for different numbers of cores: </p>

<pre class="brush: r; toolbar: false;">
summary(norm_bench$SpeedRatio[norm_bench$Cores==1])
summary(norm_bench$SpeedRatio[norm_bench$Cores==16])
</pre>

<h3>Beanplots</h3>

<p> Starring at numbers is sometimes informative, but usually only useful
    for small data sets.
    Since we humans are better in recognizing patterns in visual representations,
    <a href="http://www.jstatsoft.org/v28/c01/paper">beanplots</a> are a better
    way to make sense of the data. They are an
    elegant visualization of the distribution of measurements. </p>

<pre class="brush: r; toolbar: false;">
beanplot(SpeedRatio ~ Platform,
         data = norm_bench,
         what = c(1,1,1,0), log="",
         ylab="Runtime: noOT/OT",
         las=2)
</pre>

<p><a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/overall-distribution-beanplot.png"><img
class="aligncenter size-medium wp-image-454" title="Beanplot of the overall
distribution of all measurements"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/overall-distribution-beanplot-300x180.png"
alt="" width="300" height="180" /></a></p>


<p> This beanplot tells us, like the numbers before, that the mean is smaller
    than 1, which is the expected result and means that the indirection
    of an object table slows the VM down. However, the numbers did not tell
    use that there are various clusters of measurements that now become visible
    in the beanplot and are worth investigating. </p>

<p> Let&#8217;s look at the results split up by number of cores. </p>

<pre class="brush: r; toolbar: false;">
beanplot(SpeedRatio ~ Cores,
         data = norm_bench,
         what = c(1,1,1,0), log="",
         ylab="Runtime: noOT/OT")
</pre>

<p><a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/distribution-by-cores.png"><img
class="aligncenter size-medium wp-image-455" title="Distribution of
measurements split up by cores"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/distribution-by-cores-300x180.png"
alt="" width="300" height="180" /></a></p>

<h3>Digging Deeper</h3>

<p> While noticing that the variant without object table is faster
    for more cores, we also see that the speed ratios are distributed unevenly.
    While the bean for 1-core has a 2-parted shape, the 2-cores bean has a lot
    more points where measurements clump.
    That is probably related to the benchmarks: </p>

<pre class="brush: r; toolbar: false;">
beanplot(SpeedRatio ~ Benchmark,
         data = subset(norm_bench, Cores==2),
         what = c(1,1,1,0), log="",
         ylab="Runtime: noOT/OT", las=2)
beanplot(SpeedRatio ~ Benchmark,
         data = subset(norm_bench, Cores==16),
         what = c(1,1,1,0), log="",
         ylab="Runtime: noOT/OT", las=2)
</pre>

<p class="aligncenter"><a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/distribution-by-benchmarks-cores2.png"><img
class="size-thumbnail wp-image-457" title="Results for 2 cores"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/distribution-by-benchmarks-cores2-150x150.png"
alt="" width="150" height="150" /></a>

<a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/distribution-by-benchmarks-cores16.png"><img
class="size-thumbnail wp-image-458" title="Results for 16 cores"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/distribution-by-benchmarks-cores16-150x150.png"
alt="" width="150" height="150" /></a></p>

<p> Those two graphs are somehow similar, but you might notice that the float
    loop benchmark has a couple of strong outliers.
    I forgot the exact identifier of the float loop benchmark, so lets find out
    with this code: <code>levels(norm_bench$Benchmark)</code><br/>
    Now let&#8217;s filer the data shown by that benchmark. </p>

<pre class="brush: r; toolbar: false;">
beanplot(SpeedRatio ~ Cores,
         data = subset(norm_bench, Benchmark == "SMarkLoops.benchFloatLoop"),
         what = c(1,1,1,0), log="", ylab="Runtime: noOT/OT")
</pre>

<p><a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/float-bench-per-core.png"><img
class="aligncenter size-medium wp-image-463" title="Results for the float loop
benchmark split up by cores"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/float-bench-per-core-300x180.png"
alt="" width="300" height="180" /></a></p>


<p> This visualization reassures me, that there is something strange going on.
    The distribution of result still looks clumped as if there is another
    parameter influencing the result, which we have not regarded yet.
    The only column we have not looked at is <code>ExtraArguments</code>,
    so we will add them. Note that <code>droplevels()</code> is applied on the
    data set this time before giving it to the <code>beanplot()</code> function.
    This is necessary since the plot would contain all unused factor levels
    instead, which would reduce readability considerably. </p>

<pre class="brush: r; toolbar: false;">
beanplot(SpeedRatio ~ Cores + ExtraArguments,
         data = droplevels(subset(norm_bench, Benchmark == "SMarkLoops.benchFloatLoop")),
         what = c(1,1,1,0), log="", ylab="Runtime: noOT/OT", las=2)
</pre>

<p><a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/float-bench-per-core-and-extra-arguments.png"><img
class="aligncenter size-medium wp-image-464" title="Results of the float loop
benchmark split up by cores and extra benchmark arguments"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/float-bench-per-core-and-extra-arguments-300x180.png"
alt="" width="300" height="180" /></a></p>


<h3>Fixing up a Mistake</h3>

<p> This plot now shows us that there are three groups of results with
    different <code>ExtraArguments</code>.
    Think I forgot that the data set contains some very specific benchmarks.
    The overall goal of the benchmarks is to test the weak scaling behavior of
    the VM by increasing work-load and number-of-cores together.
    However, for the questions we are interested here, only those weak-scaling
    benchmarks are of interest.
    Thus, we need to filter out a couple of more data points, since the results
    will be unnecessarily biased otherwise.
    To filter the data points we use <code>grepl</code>.
    It matches the strings of <code>ExtraArguments</code> and allows us to
    filter out the single-core and the 10x-load benchmarks.</p>

<pre class="brush: r; toolbar: false;">
norm_bench &lt;- subset(norm_bench,
                     !grepl("^1 ", ExtraArguments)    # those beginning with "1" put load on a single core
                     &#038; !grepl("s0 ", ExtraArguments)) # those having "s0" in it put 10x load on each core
norm_bench &lt;- droplevels(norm_bench)
</pre>

<p> And since I always wanted to say that: 
    The exercise to regenerate all interesting graphs and re-answer the
    original questions are left to the interested reader. <img src='http://soft.vub.ac.be/~smarr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> 

<h2>Conclusion</h2>

<p> As a final graph, we can plot all benchmarks for all cores,
    and get an overview. The <code>par</code> function allows to adapt the
    margins of the plot, which is necessary here to get the full benchmark
    names on the plot. </p>

<pre class="brush: r; toolbar: false;">
par(mar=c(20, 4, 1, 1))
beanplot(SpeedRatio ~ Cores + Benchmark,
         data = norm_bench,
         what = c(1,1,1,0), log="",  ylab="Runtime: noOT/OT", las=2)
</pre>

<p><a
href="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/final-overview.png"><img
class="aligncenter size-medium wp-image-465" title="Overview split by number
of cores and benchmarks"
src="http://soft.vub.ac.be/~smarr/wp-content/uploads/2011/09/final-overview-300x180.png"
alt="" width="300" height="180" /></a></p>

<p> As we already knew, we see an influence of the number of cores on the
 results, but more importantly, we see most benchmarks benefitting from removing
 the extra indirection through the object table. The float loops benefit by
 far the strongest. The float objects are so small and usually used only
 temporary that avoiding the object table pays off.
 For the integer loops it does not make a difference, since the VMs uses
 immediate values (tagged integers). Thus, the integers used here are not
 objects allocated in the heap and the object table is not used either. </p>

<p> Beyond the won insight into the performance implications of an object table
    this analysis also demonstrates the benefits of using a language like
    R. Its language features allow us to filter and reshape data easily.
    Furthermore, regenerating plots and tracing steps becomes easy, too.
    Here it was necessary since some data points needed to be removed from
    the data set to get to reasonable results. Reexecuting part of the script
    or just exploring the data is convenient and done
    fast, which allows me to ask more questions about the data and understand the
    measurements more deeply. Furthermore, it is less a hassle to reassess
    the data in case certain assumptions have changed, we made a mistake,
    or the data set changed for other reasons.
    From my experience, it is much more convenient than Excel, but that might
    just be because I spend more time on learning R than on learning Excel. </p>

<p> In case you try it out yourself, you will certainly want to experiment
    with other types of visualizations, save them to files, etc.
    A few of these things can be found in my benchmarking scripts on
    GitHub: <a href="https://github.com/smarr/BenchR">BenchR</a>.</p>

<script type="text/javascript">SyntaxHighlighter.all();</script>
]]></content:encoded>
			<wfw:commentRss>http://soft.vub.ac.be/~smarr/2011/09/using-r-to-understand-benchmarking-results/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to use Pharo/Squeak from the Command-line</title>
		<link>http://soft.vub.ac.be/~smarr/2009/09/how-to-use-pharosqueak-from-the-command-line/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-use-pharosqueak-from-the-command-line</link>
		<comments>http://soft.vub.ac.be/~smarr/2009/09/how-to-use-pharosqueak-from-the-command-line/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 07:54:15 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Command-line]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Language Shootout]]></category>
		<category><![CDATA[Pharo]]></category>
		<category><![CDATA[Smalltalk]]></category>
		<category><![CDATA[Squeak]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://soft.vub.ac.be/~smarr/?p=254</guid>
		<description><![CDATA[Along the way to measure the performance of a Smalltalk implementation for commodity multi-core systems, I tried to use Pharo as a more convenient development platform. Well, and I failed in the first attempt&#8230; To remind myself and document some of the necessary steps in this environment, I wrote up the following tutorial. Command-line Scripts [...]]]></description>
			<content:encoded><![CDATA[<p>Along the way to measure the performance of a Smalltalk implementation for commodity multi-core systems, I tried to use Pharo as a more convenient development platform. Well, and I failed in the first attempt&#8230;</p>
<p>To remind myself and document some of the necessary steps in this environment, I wrote up the following tutorial.</p>

<h1>Command-line Scripts with a Headless Pharo</h1>


<p>For some tasks like benchmarking and automated testing, an integration
with other tools comes in handy.
For such use cases, Pharo can be used headless, i.e., without its  
graphical
user interface.</p>

<p>This brief tutorial will demonstrate how to use the Debian Language  
Shootout
benchmarks with a fresh Pharo image.</p>

<h2>Step 1: Setup Pharo and a Fresh Image</h2>

<ul>
  <li>download a Pharo image, the sources file, and a VM from the
    <a href="http://www.pharo-project.org/pharo-download">download page</a></li>
  <li> extract all archives in the same folder</li>
  <li> start Pharo, from the commandline, on a MacOSX it should look  
like this:
<code>"Squeak 4.2.1beta1U.app/Contents/MacOS/Squeak VM Opt" \
          pharo1.0-10418-BETAdev09.08.3.image
    </code></li></ul>

<h2>Step 2: Load OSProcess</h2>

<p>For output on the shell, we need an extra package from the SqueakSource
repository.</p>

<p>It can be loaded by simply executing the following code in a workspace  
window:
<br/>
<pre>
ScriptLoader loadLatestPackage: 'OSProcess' from:
'http://www.squeaksource.com/OSProcess'
</pre>

<p>To execute this code snippet, select it and press cmd+d or use the &#8220;do  
it&#8221;
item in the context menu.</p>

<h2>Step 3: Load Common Benchmark Code</h2>

<p>Now we can load the common parts of all shootout benchmarks into our  
image.</p>
<ul>
<li>On way to do this is to grab the code shown <a href="http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&amp;lang=squeak&amp;lang2=squeak">here</a></li> and save it to a file called <code>common.st</code>.</li>
  <li>Open the file browser from the Menu -&gt; Tools -&gt; File Browser.</li>
  <li>Select <code>common.st</code> and press <code>filein</code> to load the code.</li></ul>

<p>Now you can close all windows in your image and save and quit it.</p>

<h2>Step 4: Run a Benchmark</h2>
<ul>
<li>Grab the code of a benchmark like <a href="http://shootout.alioth.debian.org/gp4/benchmark.php?test=fannkuch&amp;lang=squeak&amp;id=1">Fannkuch</a></li>
  <li>Save it to a file named like <code>fannkuch.st</code></li>
  <li>Add a run script to the end of the code in <code>fannkuch.st</code>, like  
this:<br/>
<pre>
    Tests fannkuch.
    SmalltalkImage current snapshot: false andQuit: true.
</pre></li>
  <li>Run it with a headless Pharo:<br/>
<pre>
    "Squeak 4.2.1beta1U.app/Contents/MacOS/Squeak VM Opt" \
        -headless pharo1.0-10418-BETAdev09.08.3.image \
        $PWD/fannkuch.st 6
</pre><br/>
important is here the absolute path to the script, clearly inconvenient and uncommon on the command-line.</li></ul>
]]></content:encoded>
			<wfw:commentRss>http://soft.vub.ac.be/~smarr/2009/09/how-to-use-pharosqueak-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

