Question

I am writing a C extension for Ruby, which needs to heavily use time objects. The performance is critical for this application. How should I go about creating Time objects from C API for maximum performance? I did not find anything relevant in ruby.h include file.

Was it helpful?

Solution

I've always just used rb_time_new - it takes a time_t and a second parameter with the fractional part of the time, in microseconds.

Depending on what you are doing it might make sense to only store the time_t (and do your calculations on those) and lazily convert to ruby Time objects only when you have to

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top