can command line utilities be faster than C++? [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a project where I want to manipulate certain output files.
This can be accomplished using a combination of grep and sed and piping with |
Alternatively, I can also write a C++ program to do the same thing.
Is there a conclusive answer on which method will be faster since grep and sed should already be fairly well optimised?

From a technical standpoint, a well-written self-contained C++ program that does everything you need will be faster than using two (or more) shell commands interconnected with a pipe, simply because there will be no IPC overhead, and they can be tailor-made and optimized for your exact needs.
But unless you're writing a program that will be run 24/7 for years, you'll never notice enough gain to be worth the effort.
And the standard rules for pre-optimization apply...

If I were you, use what is already out there as these have likely been around a long time and have been tested and tried. Writing a new program yourself to do the same thing seems like a reinventing the wheel type action and is prone to error.

If you really need faster performance than you'll get with piping, you can download the source for grep and sed and tailor it to your needs in one application (be wary of licenses if you plan on distributing your code). I'd be highly surprised if you'd even notice the overhead of piping (like Flimzy mentioned), so if things are really that slow I'd start profiling your app.

It is likely that if you are a very good C/C++ programmer and spend a lot of time, that you will be able to write a program that's faster than the pipeline you're thinking of. But unless performance is so critical in this case that you absolutely must do it this way you should use the pipeline.

Related

fast on-demand c++ compilation [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm looking at the possibility of building a system where when a query hits the server, we turn the query into c++ code, compile it as shared object and the run the code.
The time for compilation itself needs to be small for it to be worthwhile. My code can generate the corresponding c++ code but if I have to write it out on disk and then invoke gcc to get a .so file and then run it, it does not seem to be worth it.
Are there ways in which I can get a small snippet of code to compile and be ready as a share object fast (can have a significant start up time before the queries arrive). If such a tool has a permissive license thats a further plus.
Edit: I have a very restrictive query language that the users can use so the security threat is not relevant. My own code translates the query into c++ code. The answer mentioning clang is perfect.
Running Clang in JIT mode should provide the speed you need, and example can be found here, safety on the other hand is something else...
Ch also had a JIT added, and seeing as its an interpreter, it might provided an easier sandboxed/controlled environment.
In addition to Necrolis answer, there's also specialized C++ parser Cling. Might come in handy.

What is Bison and why is it useful? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have been programming for a few years now and have seen the name Bison in passing, but never bothered to ask why it is or why it might be needed. How can Bison effect how I program, can it make my C/C++ code faster?
Bison is a parser generator. It takes it's input in something similar to Backus-Naur notation and outputs code to parse input according to that grammar. It lets you write a parser more easily than you would otherwise. Instead of having to do everything manually, you only have to specify the rules of your grammar and what you want to happen when it matches one of the rules.
GNU Bison is the only Bison related to programming I know of. It won't make your code faster, and it's possible that you won't ever need it in your life. However, learning some compiler theory, or even writing a simple compiler yourself, is a terrific learning experience that does affect the way you program, the way you think about computer programming, and a lot of things like that. If you enjoy formal languages and automata, you'll enjoy compiler theory; if you dislike theory in general, it's probably not for you. If you're interested, there are lots of questions about starting books on Stackoverflow.
Oh and, once in a while a programmer does need some more complicated parsing work and suchlike, and it's a huge boon to know about parser generators, instead of writing everything by hand, following a naive approach.

Finding a totally nasty, complex, Schröding-Bohr-Bug [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a really nasty bug in my program, which grew quite complex over time. It's probably the worst bug I've ever had.
I think that it might be related to a static variable initialization fiasco, but how can I ensure myself of that?
When the bug strikes, the program crashes due to heap corruption at a random point after startup, but far inside the main() function.
To be honest, I don't know what to do.
I'm on Windows 7 using Microsoft Visual Studio 2010
my program, which grew quite complex
over time
Do you keep backups of previous versions?
Find an older version that worked and continue working based on that version...
There is a famous quote out there:
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan
If this program has become more complicated than you can handle then it may be time to think about refactoring.
(This is in no way intended to be demeaning or to be taken as a personal attack...)
Run your program in the debugger, and step through the code until you see what's wrong. Place breakpoints liberally anywhere you think the bug might be caused.
Try debugging your program with gdb.

Generating word library - C or C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I need to create a simple application, but speed is very important here. Application is pretty much simple.
It will generate all available chars by saving them to text file. User will enter length that will be used for generating so the application will use recursive function with loop inside.
Will C be faster then C++ in this matter, or it does not matter?
Speed is very important because if my application needs to generate/save to file 10 million+ words.
It doesn't really matter, chances are your application will be I/O bound rather than CPU bound unless you have enough RAM to hold all that in memory.
It's much more important that you choose the best algorithm, and the best data structures to back that algorithm up.
Then implement that in the language you're most familiar with. C++ has the advantage of having easy to use containers in its standard libraries, but that's about it. You can write slow code in both, and fast code in both.

Free C++ code samples [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I would like to download some code samples (or even full projects) to learn from. The only place I know of is Sourceforge, but I want top-notch, flawless* code. Not to say there is anything wrong with SF but it's a toss up, and I don't want to learn from someones bad habits.
I've been through gametutorials.com and nehe.gamedev.net, but I would prefer to find something that's been done recently with best practices in mind.
*Obviously nothing is going to be perfect
Boost.
You could look at the source of web browsers like Chrome or Firefox.
Use an open source search engine like Koders
Qt is written pretty well.
Everyone's got different ideas of what's top-notch, as there are fundamental design trade-offs with no correct answer (e.g. performance, memory usage, maintainability, reusability/generality, simplicity, clarity, concision, portability...), and one programmer's idea of elegance is another's pompous over-engineering, and yet another's over-simplistic amateurism... :-/.
Boost code is good, but complicated by a different balance of concerns than most application code: generally portability, performance & memory usage, generality, elegance of usage, and minimising misusage are prioritised massively above simplicity, clarity or concision of implementation.
I think you're better off picking some code that does something you're interested in, then in your passion to change it you'll learn see the implications of the design compromises, good and bad. A smaller project where you can rearchitect the solution and experiment with alternatives is great. No substitute for experience.