If you use Ruby, you need not worry about performance. The language is such that it approaches an iterative approach to reading a file, line by line, and works very well. As long as you use the language in the way it was designed, you can let people translators worry about performance. Completion of the assignment.
If you need some specific readLargeFileFast method, then this should be because it really interferes with the program. Now you are writing a C program to do this, and popen is like a separate process in your ruby ββcode. You can name it read_large.c and (possibly) use command line arguments to tell you how to behave.
This defends the idea that the scripting language is used for quick development, and not for quick start. Since such a developer can be very productive due to the rapid "prototyping" of the program in something like Ruby, and only later rewriting the components guarantees some low-level code. Often, however, once it runs in a script, you donβt need to do anything at all.
Ruby Docs describe how to start a separate process and process it as a file. It is easy! A good start is the introductory paragraph of Art of Linux Programming on program modularity . This book is also a great example of using a standard linux thread editor called sed , which you could probably use with Ruby now.
If you need to parse or edit a lot of text, many interpreters or editors have been written around the sed function. Also, it can save you a lot of effort by writing something super-efficient if you donβt know C. Good - Introduction to SED by Bruce Barnett.
source share