Created
March 30, 2012 02:39
-
-
Save kbarber/2245977 to your computer and use it in GitHub Desktop.
Shaving time off facter by writing the binary in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Some facter runs on my dev box using pure ruby bin/facter: | |
| ./bin/facter 0.58s user 0.34s system 95% cpu 0.968 total | |
| ./bin/facter 0.59s user 0.34s system 96% cpu 0.964 total | |
| ./bin/facter 0.60s user 0.35s system 95% cpu 0.991 total | |
| The (somewhat condensed) ruby code of which is here: | |
| require 'facter/application' | |
| Facter::Application.run(ARGV) | |
| Now, the same version of facter, but bin/facter was replaced with a simple C equivalent: | |
| ./build/facter 0.45s user 0.30s system 94% cpu 0.795 total | |
| ./build/facter 0.46s user 0.30s system 95% cpu 0.800 total | |
| ./build/facter 0.46s user 0.31s system 96% cpu 0.803 total | |
| The C code of which is here: | |
| #include <ruby.h> | |
| int main(int argc, char *argv[]) { | |
| ruby_init(); | |
| ruby_init_loadpath(); | |
| rb_require("facter/application"); | |
| rb_eval_string("Facter::Application.run(ARGV)"); | |
| ruby_exec(); | |
| return 0; | |
| } | |
| Thats makes the C based facter binary 175 milliseconds faster on average, for this particular test. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment