# Compiling Ruby w/ Profile Guided Optimization

**URL:** <https://www.ruby-forum.com/t/compiling-ruby-w-profile-guided-optimization/60564>\
**Category:** Ruby\
**Created:** [May 15, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/compiling-ruby-w-profile-guided-optimization/60564 "2006-05-15T18:17:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Buchholz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@Greg\_Buchholz](https://www.ruby-forum.com/u/Greg_Buchholz)\
**Post date:** [May 15, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/compiling-ruby-w-profile-guided-optimization/60564/1 "2006-05-15T18:17:05Z")

</div>

Since gcc-4.1 now has the option to perform profile guided  
optimization, I thought I’d try compiling a version of Ruby with this  
feature turned on. For the (somewhat contrived/synthetic) scenario  
below, it looks like compiling with profile guided optimization turned  
on, along with -O3, results in about a 9% speed increase vs. -O3 alone.  
YMMV. I compiled a version of Ruby-1.8.4 using the following config  
options…

```
configure CFLAGS="-O3 -fprofile-generate" LDFLAGS=-fprofile-generate

```

…Then I ran the short version of the n-body program from the Great  
Computer Language Shootout with n=1000…

[http://shootout.alioth.debian.org/debian/benchmark.php?test=nbody&lan](http://shootout.alioth.debian.org/debian/benchmark.php?test=nbody&lan)…

…this generated the profile information needed for the next stage. I  
then compiled a Ruby with…

```
configure CFLAGS="-O3 -fprofile-use"

```

…Running the resulting interpreter runs the exact same n-body program  
about 8-10% faster than an compiling with just -O3.

FWIW,

Greg Buchholz
