# Running ruby script from my own .NET code is slow

**URL:** <https://www.ruby-forum.com/t/running-ruby-script-from-my-own-net-code-is-slow/194879>\
**Category:** IronRuby\
**Created:** [September 13, 2010, 1:19am UTC](https://www.ruby-forum.com/t/running-ruby-script-from-my-own-net-code-is-slow/194879 "2010-09-13T01:19:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Anton\_F](https://www.ruby-forum.com/u/Anton_F)\
**Post date:** [September 13, 2010, 1:19am UTC](https://www.ruby-forum.com/t/running-ruby-script-from-my-own-net-code-is-slow/194879/1 "2010-09-13T01:19:33Z")

</div>

Hi all!

Why it is ~5 times slower to run the same .rb script from my .NET  
application (using ScriptEngine and ScriptRuntime) classes, than doing  
the  
same with ir.exe?  
When I downloaded IronRuby source, and compiled ir.exe (Ruby.Console),  
it  
was 2 times slower, than ir.exe in released binaries. (But still 3 times  
faster than running scripts from my own application)

Any ideas, what is behind these differences?

---

<div class="post-metadata">

**Author:** ![Anton\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Anton\_F](https://www.ruby-forum.com/u/Anton_F)\
**Post date:** [September 13, 2010, 1:24am UTC](https://www.ruby-forum.com/t/running-ruby-script-from-my-own-net-code-is-slow/194879/2 "2010-09-13T01:24:49Z")

</div>

Can you give an example of what script it is and how you exactly run it  
from the .NET app?

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Anton F.  
Sent: Sunday, September 12, 2010 4:18 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] running ruby script from my own .NET code is  
slow

Hi all!

Why it is ~5 times slower to run the same .rb script from my .NET  
application (using ScriptEngine and ScriptRuntime) classes, than doing  
the same with ir.exe?  
When I downloaded IronRuby source, and compiled ir.exe (Ruby.Console),  
it was 2 times slower, than ir.exe in released binaries. (But still 3  
times faster than running scripts from my own application)

Any ideas, what is behind these differences?

---

<div class="post-metadata">

**Author:** ![Anton\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Anton\_F](https://www.ruby-forum.com/u/Anton_F)\
**Post date:** [September 13, 2010, 1:37am UTC](https://www.ruby-forum.com/t/running-ruby-script-from-my-own-net-code-is-slow/194879/3 "2010-09-13T01:37:42Z")

</div>

Here is the code:  
[http://paste.dprogramming.com/dpk25ghd](http://paste.dprogramming.com/dpk25ghd)  
(It’s just a dummy speed test)

I tried several ways to call it:  
runtime = Ruby.CreateRuntime();  
engine = Ruby.GetEngine(runtime);

#than  
engine.ExecuteFile(“test.rb”);  
#or  
engine.CreateScriptSourceFromFile(“lib.rb”).Execute()  
#or  
CompiledCode code =  
engine.CreateScriptSourceFromFile(“test.rb”).Compile();  
code.Execute();

Actually they all give the same results…

2010/9/13 Tomas M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Anton\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Anton\_F](https://www.ruby-forum.com/u/Anton_F)\
**Post date:** [September 24, 2010, 5:59pm UTC](https://www.ruby-forum.com/t/running-ruby-script-from-my-own-net-code-is-slow/194879/4 "2010-09-24T17:59:17Z")

</div>

Hi,

I still have this performance problem. I think there must be a reason,  
and  
it could be solved somehow. Really no ideas?

Anton

2010/9/13 Anton F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
