Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Whaa? I'd expect a C++ program written using strings & iostreams to be at least 10x slower than an equivalent program in perl.Traditional languages like C++ are harder to learn, but much faster.
Whaa? I'd expect a C++ program written using strings & iostreams to be at least 10x slower than an equivalent program in perl.
I would normally pick Perl because it is often faster in terms of Programmer time.
I would expect a well written C/C++ program to be faster cpu wise, but for the majority of parsing tasks the extra programmer time isn't worth it IMO.
And I wouldn't expect the C/C++ programs to be slower than perl. If you are going to do an intense parsing task, anyone with any kind of sense won't use C strings.
Well - C strings are not that bad. C++ std::string probably have more overhead; no idea how much.
The result in the thread I linked was that the fastest result was from a C++ program (written as C with classes, not idiomatic C++) treating the file as a bunch of bytes.
For that task I think C strings would have been fine, because you're not doing lots of string chopping/concatenating/reordering and shuffling them around, which is where c strings really start to get annoying.
If you were doing some kind of operation where you were transforming an xml file or something in some big way, then C strings would be pretty slow compared to a pascal type string where the length is stored along with the string, or some other improved string class.
Why so? Are you referring to any program in general, or a program specific to the OP's needs (which, at this point, you don't know)? I'm not sure how you can formulate such an assertion, not to mention find a reason to stick by it. What tests have you run to substantiate your opinion?I'd expect a C++ program written using strings & iostreams to be at least 10x slower than an equivalent program in perl.
I can try digging around, but it's pretty unlikely. Did you send it to me in email? Do you remember which address I was using for that thread? Or was I making people give download points?edit: Long shot. Mikeblas, do you think you have my program from that lying around? (sqlfix.zip or .cpp , I guess).
Why so? Are you referring to any program in general, or a program specific to the OP's needs (which, at this point, you don't know)? I'm not sure how you can formulate such an assertion, not to mention find a reason to stick by it. What tests have you run to substantiate your opinion?
I can try digging around, but it's pretty unlikely. Did you send it to me in email? Do you remember which address I was using for that thread? Or was I making people give download points?
Download points, I'm afraid.
I know where I have a copy - I'll just grab it next time I visit my parents. Don't stress, I was just wondering if you happened to have every single forum-related thing lying around sorted by year, or something.![]()
Not quite that crazy, sorry. I might have a backup of the machine I was using around, if I could remember what machine name was my main home dev rig at that time ...
The OP said he needed a parser that doesn't do anything - it just stops parsing when it hits the right expression. The overhead of calling a bunch of virtualized IO functions and encapsulating incoming text into objects is going to be huge for a parser that isn't actually doing anything with its tokens, even if it happens to have quite a few states.Why so? Are you referring to any program in general, or a program specific to the OP's needs (which, at this point, you don't know)? I'm not sure how you can formulate such an assertion, not to mention find a reason to stick by it. What tests have you run to substantiate your opinion?
Really depends on your previous programming experience and comfort- if you still need suggestions, some background and context would be great.
Lots of dependencies affect your decision, so it's hard to recommend a language without knowing more specifics.
For me it was important that the solution be cross platform, is that an issue for you?
Python is indeed decent. It has fewer text processing shortcuts than Perl, but the tradeoff is that it's much easier to read (and probably learn).
Perl/Python are definite contenders if you want flexible reporting tools but don't neglect the traditional unix awk/sed/grep tools.
The OP said he needed a parser that doesn't do anything - it just stops parsing when it hits the right expression. The overhead of calling a bunch of virtualized IO functions and encapsulating incoming text into objects is going to be huge for a parser that isn't actually doing anything with its tokens, even if it happens to have quite a few states. I can't be the only one who feels that this is obvious because, while several posters in the thread you linked used OO languages, only one person bothered to try breaking the problem down using a proper OO approach. OTOH, it looks like he was the only one to submit a correct program. There is an argument to be made that perl is an OO language with backwards compatibility like C++, but IMO that would be incorrect because perl does not have an OO library.
He says it'll tokenize, then stop. Tokenization is work. Looks like might not be what he meant, but it certainly is what he said before your post. He might have meant scan and stop, and that's entirely different. Either way, I see no advantage to Python or Perl aside from some ease of development, but even that is conditional because of the limitations inherent in those languages.The OP said he needed a parser that doesn't do anything - it just stops parsing when it hits the right expression.
It won't be huge, but it can be important. But who said anything about virtual I/O? I think all the I/O the program would do is physical. Or do you mean virtual functions? The indirection of a virtual function isn't huge by any stretch of the imagination.The overhead of calling a bunch of virtualized IO functions and encapsulating incoming text into objects is going to be huge
People are often wrong in groups.I can't be the only one who feels that this is obvious because, while several posters in the thread you linked used OO languages, only one person bothered to try breaking the problem down using a proper OO approach. OTOH, it looks like he was the only one to submit a correct program. 8)
You're simply, then, looking for a string within a file? What of the tokenization you mentioned earlier?I am traditional C++ programmer. I have worked in the past briefly with Perl and Python. The need for the program is to be run on a large text file, seeking a keyword or keyphrase to use to truncate the file at that discovery point. Speed would be good. It would run from a a Windows environment with access to Cygwin.
Good catch! Unfortunately, no backups of that machine remain.
I wasn't sure if tokenization was needed to make strings from the parse to use to compare to the search keyword or key-phrase. Once that match is found, I then need to truncate the file, so replace the match with a line break and an EOF.
Fooey
Bunky
/* bar */
Zing
bar
Blap!
If you're too dumb to think it through, sure.1 word, python.
#!/usr/bin/perl
open IF, "<inputfile.txt"; #input file, the file you're reading
open OF, ">>outputfile.txt"; #output file, the file you're writing to
$word="whatever"; #word we're looking for
while (<IF>){
if ($_ =~ /^[^#]+$word/){
print OF $_ . "\n"; close OF; close IF; die "Pattern matched";}
else{print OF $_ . "\n";}
}
close IF; close OF;
The OP said he needed a parser that doesn't do anything - it just stops parsing when it hits the right expression. The overhead of calling a bunch of virtualized IO functions and encapsulating incoming text into objects is going to be huge for a parser that isn't actually doing anything with its tokens, even if it happens to have quite a few states.
There is an argument to be made that perl is an OO language with backwards compatibility like C++, but IMO that would be incorrect because perl does not have an OO library.
Nothing wrong with Perl or Python; the problem is one-word answers.At the risk of threaddrift an unwarranted flaming, I've done text manip in python and perl..
The only functional problem is that you're processing line by line. The only performance problem (other than using an interpreted language) is that you're using regular expressions where string matching will do.I'm no perl expert though, that's just how I'd start my go at it. I'd have to put more thought into it if multiline comments (ala php) came into play.
Nothing wrong with Perl or Python; the problem is one-word answers.
The only functional problem is that you're processing line by line. The only performance problem (other than using an interpreted language) is that you're using regular expressions where string matching will do.
A regex needs to parse the regex, worry about all the wildcards and repeaters, and so on. If you need all those features, it's great. Here, I don't think we do -- we still haven't heard back from the OP with clear specifications.
If we don't need those features, seaching for a simple substring is lots faster. You can do that with the index functio
Yes; they're to be avoided unless necessary, when perf counts. Arguably, you should always avoid them because of complexity.