昨日の xml 読込み で,データが大きい場合に比例ではなく極端に遅くなる?
それで,次の様なコードで計測してみた.
bool Test (c_tstring& str) { for (size_t index=0 ; index<str.size() ; index++) { ElapseTime et ; tstring s_str = ::Parse_xml_quot(str,_T('|'), &index) ; std::cerr << ::To_tstring_Ki(long(s_str.size())) << _T("\t") << et.GetElapse() << std::endl ; } return true ; } bool Test (void) { tstring outPath = ::Get_i_Tools_tmp_date() ; tstring now_hms = ::Now_Format(_T("%H%M%S")) ; tstring out_txt = ::Path_AddLastSP(outPath) + now_hms + _T(".txt") ; tstring outrtxt = ::Path_AddLastSP(outPath) + now_hms + _T("_.txt") ; tstring str ; { v_tstring strAry ; { tstring str_1000 ; { tstring str_10 = _T("0123456789") ; for (long indexS=0 ; indexS<100 ; indexS++) { str_1000 += str_10 ; } } for (long index=0 ; index<2000 ; index++) { strAry.push_back(str_1000) ; } } str = ::String_Join_Line(strAry) ; } str[0] = _T('|') ; str += _T('|') ; size_t len = str.length() ; while (len > 100) { len = len/2 ; str[len-0] = _T('|') ; str[len-1] = _T('|') ; } { tstring tmp = str ; v_tstring tmpAry = ::String_Split(tmp.c_str(),false) ; tmpAry = ::SkipEmpty(tmpAry) ; str = ::String_Join_Line(tmpAry) ; } { ::SaveUTF8(out_txt.c_str(),str) ; ::Test(str) ; } { tstring rev = str ; { std::reverse(rev.begin(),rev.end()) ; v_tstring revAry = ::String_Split(rev.c_str(),false) ; revAry = ::SkipEmpty(revAry) ; rev = ::String_Join_Line(revAry) ; } ::SaveUTF8(outrtxt.c_str(),rev) ; ::Test(rev) ; } return true ; }
DS116 では,比例と思われる.
login as: Iwao Iwao@DS116's password: Iwao@DS116:~$ source ./set_ds_inc.sh Iwao@DS116:~$ cd gcc_test/Test/T_P_xm_q/ Iwao@DS116:~/gcc_test/Test/T_P_xm_q$ g++ T_P_xm_q.cpp Iwao@DS116:~/gcc_test/Test/T_P_xm_q$ ll total 204 drwxrwxrwx+ 2 Iwao users 4096 Jan 8 14:10 . drwxrwxrwx+ 10 Iwao users 4096 Jan 8 14:09 .. -rwxrwxrwx 1 Iwao users 183528 Jan 8 14:10 a.out -rwxrwxrwx+ 1 Iwao users 3009 Jan 8 13:59 T_P_xm_q.cpp Iwao@DS116:~/gcc_test/Test/T_P_xm_q$ ./a.out 61 0.000384092 61 6.10352e-05 122 5.31673e-05 245 5.19753e-05 489 6.29425e-05 979 8.70228e-05 1.91 K 0.000140905 3.82 K 0.000212908 7.64 K 0.000381947 15.29 K 0.000729799 30.58 K 0.00145721 61.16 K 0.0028069 122.32 K 0.00562811 244.63 K 0.011224 489.26 K 0.0223849 978.52 K 0.0462639 0 5.38826e-05 0 3.91006e-05 978.52 K 0.045109 489.26 K 0.022413 244.63 K 0.0112309 122.32 K 0.00556397 61.16 K 0.00286198 30.58 K 0.00143504 15.29 K 0.000734806 7.64 K 0.000383139 3.82 K 0.000211 1.91 K 0.000123024 979 8.51154e-05 489 6.19888e-05 245 5.00679e-05 122 4.3869e-05 61 4.00543e-05 61 3.91006e-05 0 3.31402e-05 0 3.31402e-05 Iwao@DS116:~/gcc_test/Test/T_P_xm_q$
VC 6 は比例でなく,もっとかかっている.VC 14 では問題ない.VC 8 以降?は大丈夫だと思う.
C:\Users\Iwao>C:\Users\Iwao\AppData\Local\Temp\MICS.tmp\Temp\Test.exe\T_P_xm_q.exe 61 0 61 0 122 0 245 0 489 0 979 0 1.91 K 0 3.82 K 0 7.64 K 0 15.29 K 0 30.58 K 0.016 61.16 K 0.016 122.32 K 0.109 244.63 K 0.531 489.26 K 2.433 978.52 K 14.68 0 0 0 0 978.52 K 14.664 489.26 K 1.342 244.63 K 0.374 122.32 K 0.125 61.16 K 0.016 30.58 K 0.015 15.29 K 0 7.64 K 0 3.82 K 0 1.91 K 0 979 0 489 0 245 0 122 0 61 0 61 0 0 0 0 0 C:\Users\Iwao>
tstring Parse_xml_quot (c_tstring& str,const TCHAR qm,size_t* index) { tstring q_str ; if (*index < str.length()) { TCHAR c = str[*index] ; if (c == qm) { /* q_str += c ; for (size_t indexQ=*index+1 ; indexQ<str.size() ; indexQ++) { TCHAR cq = str[indexQ] ; q_str += cq ; if (cq == qm) { *index = indexQ ; break ; } } */ size_t pos = ::String__Find(str,qm,*index+1) ; if (pos == tstring::npos) { q_str = str.substr(*index) ; *index = str.length() ; } else { size_t q_len = pos+1 - *index ; q_str = str.substr(*index,q_len) ; *index = pos ; } } } return q_str ; }
2019/06/06
2019/01 のコードは属性の値のネスト(attr='”a” “b”‘)に対応できてないバグあり.
[…] に書いた xml の読込み で,属性が次の様になっている場合うまく処理できないバグがあった. […]