[prev in list] [next in list] [prev in thread] [next in thread]
List: aspell-user
Subject: Re: [Aspell-user] Reg. performance of suggestions
From: Kevin Atkinson <kevina () gnu ! org>
Date: 2005-07-19 17:19:14
Message-ID: 20050719111128.S82035-200000 () slash ! flux ! utah ! edu
[Download RAW message or body]
On Mon, 18 Jul 2005, Ananda Kumar C wrote:
> Thanks a lot for your input. The performance has grown now, but I have an
> interesting observation.
> I had run my tests against both the 0.60.3 and 0.60.2 versions. My test
> program randomly picks up a word from a really huge list of words (around
> 1.2 M words) and tests the words for correct spelling.
> If a word is misspelt, I get the suggestions. The sug-mode config is now
> set to ultra.I run this test until I get around 500 misspelt words.
>
> The results are as follows :
> +--------------------------+-----------------+------------------+
> | | ver. 0.60.3 | ver. 0.60.2 |
> +--------------------------+-----------------+------------------+
> |Avg. time for checking | 17 microsecs | 6 microsecs |
> |Avg. time for suggesting | 2087 microsecs | 1029 microsecs |
> +--------------------------+-----------------+------------------+
Those are not the results I am getting:
ver. 0.60.2:
check avg: 13
sug avg: 4861
ver. 0.60.3:
check avg: 13
sug avg: 3884
I modified your program a bit to print the average at the end. Attached
is a modified copy.
I don't know why you are getting worse results with Aspell 0.60.3. You
should't.
I am using Gcc 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
["spell_time.cpp;" (spell_time.cpp;)]
#include <aspell.h>
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
#include <sys/time.h>
#include <fstream.h>
using namespace std;
enum TimerAction { TIMER_ACTION_START, TIMER_ACTION_END };
#define TIMER_START() Timer(TIMER_ACTION_START)
#define TIMER_END(x,var) do {\
int t = Timer(TIMER_ACTION_END);\
cout << "Time taken for " << x << " : " << t << " us." << endl;\
var.total += t;\
var.count++;\
} while (false)
int Timer(TimerAction action)
{
static struct timeval begin;
struct timeval end;
long retval;
if (action == TIMER_ACTION_START)
{
retval = gettimeofday(&begin, NULL);
}
else
{
gettimeofday(&end, NULL);
retval = (end.tv_sec-begin.tv_sec)*1000*1000 + (end.tv_usec-begin.tv_usec);
}
return retval; /* No. of microseconds since timer was started */
}
struct Stat {
int total;
int count;
};
int main()
{
Stat other = {0,0};
Stat check = {0,0};
Stat sug = {0,0};
/* New config object */
AspellConfig *spell_config = new_aspell_config();
/* Set conf */
aspell_config_replace(spell_config, "lang", "en_US");
aspell_config_replace(spell_config, "sug-mode", "ultra");
/* New speller object */
AspellCanHaveError *possible_err = new_aspell_speller(spell_config);
AspellSpeller *spell_checker = NULL;
if (aspell_error_number(possible_err) != 0) {
cout << "ASPELL Error : " << aspell_error_message(possible_err) << endl;
return 1;
}
else {
spell_checker = to_aspell_speller(possible_err);
}
/* Load the word list from the file */
ifstream wordStream("/home/kevina/aspell-time/spell/words.lst");
if (wordStream.is_open() == false) {
cout << "Word list cannot be opened" << endl;
return 2;
}
string aWord;
vector<string> wordList;
while (wordStream.eof() == false) {
wordStream >> aWord;
if (wordStream.eof() == false) {
wordList.push_back(aWord);
}
}
wordStream.close();
int iteration = 1;
do {
char input[80];
int randIndex = random() % wordList.size();
aWord = wordList[randIndex];
strcpy(input, aWord.c_str());
int isCorrect;
/* Check if the word is correct */
TIMER_START();
isCorrect = aspell_speller_check(spell_checker, input, -1);
TIMER_END("checking a word for correct spelling", check);
if (isCorrect == 0) {
/* Inc(Iteration) if word is misspelt */
iteration++;
cout << "\"" << input << "\"" << " is misspelled." << endl;
/* Get the suggestion for a misspelt word */
TIMER_START();
const AspellWordList *suggestions = aspell_speller_suggest(spell_checker, input, -1);
TIMER_END("getting a list of suggestions from aspell", sug);
AspellStringEnumeration *elements = aspell_word_list_elements(suggestions);
const char *aSuggestion;
int i = 1;
while ((aSuggestion = aspell_string_enumeration_next(elements)) != NULL) {
if (i == 1) {
cout << "Suggestions :-" << endl;
cout << "------------ " << endl;
}
cout << i++ << ". " << aSuggestion << endl;
}
delete_aspell_string_enumeration(elements);
}
else {
cout << "\"" << input << "\"" << " is correctly spelled." << endl;
}
cout << "WORD LENGTH : " << strlen(input) << endl;
} while (iteration <= 500);
/* Delete the object before quitting */
delete_aspell_config(spell_config);
delete_aspell_speller(spell_checker);
cout << "check avg: " << check.total/check.count << endl;
cout << "sug avg: " << sug.total/sug.count << endl;
return 0;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic