Blame view

morfeusz/fsa/test_speed.cpp 1.26 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
12
/* 
 * File:   test_speed.cpp
 * Author: mlenart
 *
 * Created on 24 październik 2013, 17:47
 */

#include <cstdlib>
#include <fstream>
#include "fsa.hpp"
#include "utils.hpp"
Michał Lenart authored
13
//#define NDEBUG
Michał Lenart authored
14
15
16
17
18
19
20
21
22
23

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    validate(argc == 3, "Must provide exactly two arguments - FSA filename and test data filename.");
    const unsigned char* fsaData = readFile(argv[1]);
    StringDeserializer deserializer;
Michał Lenart authored
24
    FSA<char*>* fsa = FSA<char*>::getFSA(fsaData, deserializer);
Michał Lenart authored
25
26
27
    ifstream ifs;
//    ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    ifs.open(argv[2], ios::binary);
Michał Lenart authored
28
29
30
31
    char line[65536];
    int recognized = 0;
    int unrecognized = 0;
    while (ifs.getline(line, 65536, '\n')) {
Michał Lenart authored
32
        char* val;
Michał Lenart authored
33
        if (fsa->tryToRecognize(line, val)) {
Michał Lenart authored
34
35
//            printf("%s: *OK*\n", line);
            recognized++;
Michał Lenart authored
36
37
        }
        else {
Michał Lenart authored
38
            unrecognized++;
Michał Lenart authored
39
//            exit(1);
Michał Lenart authored
40
//            printf("%s: NOT FOUND\n", line);
Michał Lenart authored
41
42
        }
    }
Michał Lenart authored
43
44
45
    cout << "recognized: " << recognized << endl;
    cout << "unrecognized: " << unrecognized << endl;
    cout << "total: " << (recognized + unrecognized) << endl;
Michał Lenart authored
46
//    cout << "transitions visited: " << fsa->transitionsCount() << endl;
Michał Lenart authored
47
48
    return 0;
}