Parsing input and performance of QRegExp
-
Hi!
I need to parse some input. The input is a poker handhistory-file.
You can view an example here: "http://pastebin.com/rzhccyfK":http://pastebin.com/rzhccyfKI need the following informations:
- All Playernames
- Gamenumber
- All costs (and of each player)
Let's say i have to get all information to put in a database and to examine the data.
My first try was "use regular expressions" and use boost::spirit.
I find out that regular expressions are much slower than parsing with boost::spirit. The problem with spirit is that it takes a long time to compile. Very long, but it's fast as hell!
What would you suggest? Use another parser? QLALR?
Can i parse the following with QLALR?
Input1: Player raises $1 to $2 (Name: Player, amount $2)
Input2: Player raises raises $1 to $2 (Name: Player raises, amount $2)And...another thing? Is it fast?
What's with other parsers? Any experience with Ragel, Bison or something else?
Nex thing: Performance of QRegExp!
I did a test with the following code:
@void MainWindow::on_btnTest_clicked()
{
int i = TestRegex();
qDebug() << "Dauerte: " << i << "\n";
}int MainWindow::TestRegex()
{
list.clear();qDebug() << "Start\n"; tgone.start(); regex.setCaseSensitivity(Qt::CaseInsensitive); regex.setPatternSyntax(QRegExp::RegExp2); regex.setPattern("^(\\d{2,2})\\.(\\d{2,2})\\.(\\d{4,4})$"); if(regex.isValid()) { int i=0; i++; for(i=0; i<5000; i++) { if (regex.indexIn("12.03.2011") != -1) { list.append(regex.cap(0)); list.append(regex.cap(1)); list.append(regex.cap(2)); } } } qDebug() << "Elemente: " << list.count() << "\n"; return tgone.elapsed();
}@
If i run the code for the first time the used time is 71 ms, on second run 400, on third 501. It grows!! But why?
I know that other frameworks need to compile a regexe, why is there no need for QRegExp?
Thank you very much! Im really interested in your answers!!!
-
[quote author="jensen82" date="1311268345"]
If i run the code for the first time the used time is 71 ms, on second run 400, on third 501. It grows!! But why?
[/quote]This looks like you might not be resetting your timer tgone. It seems to always show the time since the first run. Could that be the issue here?
Apart from that, memory allocation MIGHT be an issue here (but I don't think so). You could try to preallocate using:
@
list.reserve(5000 * 3);
@