From d00d56e293a56251997b4fe79a7380ae230d97b5 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 21 Dec 2015 10:30:57 +0000 Subject: [PATCH] Aggiunto test hashtable git-svn-id: svn://10.65.10.50/branches/R_10_00@23156 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba1200.cpp | 80 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/ba/ba1200.cpp b/ba/ba1200.cpp index c43318b9e..dd9eb6f9e 100755 --- a/ba/ba1200.cpp +++ b/ba/ba1200.cpp @@ -406,31 +406,56 @@ bool TTest_application::test7(TLog_report& log) return ok; } +ostream* _out = NULL; + +static void str_serialize(const TObject& obj) +{ *_out << obj << '\n'; } + +static bool str_deserialize(istream& i, TString& str) +{ + char* buff = str.get_buffer(50); + bool in_string = false; + while (!i.eof()) + { + char c = '\0'; i.get(c); + if ((c > '\0' && c < '0') || (c > '9' && c < '@') || (c>'Z' && c < 'a')) + { + if (in_string) + break; + } + else + { + *buff = c; + buff++; + in_string = true; + } + } + *buff = '\0'; + return in_string && str.full(); +} + bool TTest_application::test8(TLog_report& log) { static TArray parole(1024*1024); - if (parole.empty()) + TString msg; + + const bool first_time = parole.empty(); + if (first_time) { - const clock_t start = start_progind(n, TR("Lettura big.txt con TArray")); - TString str; + TString80 str; + msg = TR("Lettura big.txt con TArray"); + log.log(0, msg); + const clock_t start = start_progind(1, msg); ifstream big("recdesc/big.txt"); - while (!big.eof()) + while (str_deserialize(big, str)) { - big >> str; - if (str.full()) - { - str.trim(); - if (str.len() <= 16) - parole.add(new TString16(str)); - else - parole.add(new TString80(str)); - } + parole.add(str); + _pi->add_status(0L); } stop_progind(); } - TString msg; const unsigned int n = parole.items(); bool ok = n > 0; @@ -449,12 +474,22 @@ bool TTest_application::test8(TLog_report& log) } } const clock_t t = stop_progind() - start; - msg.format("Lettura %ld parole in TAssoc_array %6ld msec - %5lg words per sec", n, t, 1000.0*n/t); + msg.format("TAssoc_array %ld(%ld) parole %6ld msec - %5lg wps", n, ass.items(), t, 1000.0*n/t); log.log(0, msg); + + if (first_time) + { + TFilename fn; fn.tempdir(); fn.add("assoc.txt"); + _out = new ofstream(fn); + ass.for_each(str_serialize); + _out->flush(); + delete _out; + _out = NULL; + } } if (ok) { - THash_table ash; + THash_table ash(1024*36); const clock_t start = start_progind(n, TR("Lettura big.txt con THash_table")); FOR_EACH_ARRAY_ITEM(parole, r, o) { @@ -467,8 +502,19 @@ bool TTest_application::test8(TLog_report& log) } } const clock_t t = stop_progind() - start; - msg.format("Lettura %ld parole in THash_table %6ld msec - %5lg words per sec", n, t, 1000.0*n/t); + msg.format("THash_table %ld(%ld) parole %6ld msec - %5lg wps", n, ash.items(), t, 1000.0*n/t); log.log(0, msg); + + if (first_time) + { + TFilename fn; fn.tempdir(); fn.add("hash.txt"); + _out = new ofstream(fn); + ash.for_each(str_serialize); + _out->flush(); + delete _out; + _out = NULL; + } + } if (!ok)