0

Came across IronRuby and thought it was pretty interesting. Decided to give it a try.

I have some ruby scripts that I would like to distribute. However, my audience may or may not have ruby installed on their systems, but they would have .net, so I thought I'll just write bundle together a C# GUI along with the iron ruby dll's so that they can run these ruby scripts without having to install ruby. And I could also take advantage of making GUI's in C#.

So I decided to test it by simply running a file

ScriptEngine engine = Ruby.CreateEngine();
engine.ExecuteFile("hello_world.rb");

hello_world.rb contains one line

3.times { p 'hello' }

Then I let my application run and wait...
Several seconds later it printed hello to the console 3 times.

Is it supposed to take a long time for it that ruby engine? I guess I could start the engine and then leave it running for the duration of the program, but having to wait for it to start up can be boring.

I am using IronRuby 1.0 built for .net 2.0 if it makes a difference (I haven't tried 1.1 but it's advertised for .net 4 which I don't want to use)

MxLDevs
  • 19,048
  • 36
  • 123
  • 194

1 Answers1

1

It's probably just the JIT compiling everything at the beginning. If you want to test this out, execute a different script right after the hello world one, it should print to the console instantaneously.

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
  • Yes, you're right. The rest of the scripts were executing immediately after the first one. Is there a way to cut the load time? I could always toss in a cute animation to distract their attention I suppose. – MxLDevs Jul 30 '12 at 03:33
  • When the application first loads up you can try running a blank script (or one that does a single operation) to get the JIT to compile it all before the application starts up. (You could also spin off another thread when the GUI starts and gray out the "run" button until it's done loading. Some "Loading IronRuby" text might be useful if it takes too long) – Robert Rouhani Jul 30 '12 at 03:41
  • Sounds like a good solution. Users probably won't be starting up the app and then immediately trying to run the ruby scripts. – MxLDevs Jul 30 '12 at 03:42
  • @Keikoku Ah, but if you want to include file associations later on down the track they might be :) – Simon Whitehead Jul 30 '12 at 03:46
  • I didn't think of that! But I probably won't include them for a small tool anyways. – MxLDevs Jul 30 '12 at 03:52
  • If you want file associations, then you're probably going to be distributing the app in an installer format, which means that you can invoke `NGen` (or `aot` with Mono) to pre-compile IronRuby for that machine. You could also install IronRuby to the GAC and it'll take care of the pre-compilation for you. – Robert Rouhani Jul 30 '12 at 04:13