DEV Community

Creating Ruby native extensions

Vinicius Stock on April 09, 2019

Note Since the time this post was written, the ext option has been added to bundler, which automatically configures a new gem to be a na...
Collapse
 
ashwinv11 profile image
Ashwin Vaswani

Cool! I haven't created a native extension yet but this got me researching other alternatives and I found Helix, looks like it lets you write type safe performant Ruby classes in Rust. What's really interesting is that you can use any arbitrary Rust crate in your code.. Gonna have to find a reason to use this 😄

Collapse
 
vinistock profile image
Vinicius Stock

I haven't used Helix before, but it does seem interesting. I know there are other alternatives for writing native exntesions in Crystal and in Java. I wonder if they differ significantly in performance.

Collapse
 
mykhailokrainik profile image
Mykhailo Krainik

As told there usehelix.com/roadmap#performance-p...

Performance parity with C
In general, Rust is in the same performance ballpark as C for code >written in Rust (sometimes it’s even faster). However, the cost of >crossing from Ruby to Rust is still high (compared to Ruby C >extensions).

That being said, because using native code is so much faster than >Ruby, you can recoup the cost difference pretty quickly. This >problem is more important for chatty APIs, or drop-in replacements >for Ruby APIs that intrinsically require a lot of communication with >Ruby (e.g. to_str).

Collapse
 
emma_snow_e23a71179881a92 profile image
Emma Snow

CGPA (Cumulative Grade Point Average) is a grading system used by many educational institutions to evaluate a student’s overall academic performance. To convert CGPA to percentage, a commonly used formula is: Percentage = CGPA × 9.5 (may vary by institution). This conversion helps in standardizing scores for applications, such as higher studies or job placements, where percentages are required.

Collapse
 
ylluminarious profile image
George Plymale II
Collapse
 
cobey26265 profile image
cobey

Creating Ruby native extensions involves writing code in C (or sometimes C++) that can be used within Ruby to perform operations that are GPA to Percentage Converter either too low-level or performance-critical for pure Ruby.

Collapse
 
cgpatopercent profile image
Cgpa to percentage

You're right! Creating Ruby native extensions allows developers to leverage the performance of C or C++ for tasks that require high efficiency. This approach can be particularly useful for building tools like a KTU CGPA calculator, where performance and low-level operations are crucial for accurately converting GPA to percentage. By using native extensions, we can ensure that such converters run efficiently while integrating seamlessly with Ruby applications.

Collapse
 
janvi_48e393ff3f4f4d7afa2 profile image
janvi

Great insight! Native extensions truly bridge the gap between Ruby's simplicity and the raw power of C/C++. This combination ensures both precision and efficiency for tasks requiring high performance. For anyone interested, here's a handy tool for converting SGPA to Percentage, which might be useful in similar scenarios.

Collapse
 
tool_site_ef010e6e2c0167e profile image
Tool Site

Great update! Using --ext with bundle gem definitely simplifies native extension setup. I recently explored this process in a write-up on Ruby internals and performance trade-offs over at ouruniversitypedia.com—might be helpful for folks diving deeper into native extensions.

Collapse
 
hexix18006 profile image
hexix

Creating Ruby native extensions allows you to write performance-critical code in C (or C++) while integrating it into your terabox no ads mod apk Ruby application.