19. September, 2007
19. September, 2007
in by Michael Neumann

You wouldn’t use Ruby for a high-performance pulsed neural network simulator, would you? The one I wrote is actually in C++, but I really consider to rewrite it in Ruby plus C.

The reason is that there is so much code that isn’t performance critial at all (loading and dumping of neural nets for example) and which is quite ugly to do in C++. Ruby on the other hand gives me a lot of things for free:

  • a garbage collector
  • dynamic arrays
  • strings
  • exceptions

The performance of the garbage collector isn’t a problem at all because during the simulation no new objects are created. As such, the garbage collector will only run very few times. The use of a garbage collector even makes it quite easy to modify the neural net at runtime without introducing memory leaks. You get headache to try the same in C++.

Then the performance of dynamic arrays and strings in Ruby is comparable to the equivalents in C++ (std::vector and std::string). And you don’t get memory leaks :).

Then everything else gets so much easier. I can reuse the JSON parser of Ruby. I can make a web-service out of the simulator easily. New neuron types could be prototyped in Ruby and then later converted to C for high performance. And a lot more.