2 ** Copyright 2003, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
12 #include <Application.h>
13 #include <StopWatch.h>
16 #include <HashMapCatalog.h>
22 const uint32 kNumStrings
= 10000;
24 BString strs
[kNumStrings
];
25 BString ctxs
[kNumStrings
];
27 BString trls
[kNumStrings
];
29 const char *translated
;
35 void TestIdCreation();
39 #define B_TRANSLATION_CONTEXT "CatalogSpeed"
41 #define catSig "x-vnd.Be.locale.catalogSpeed"
42 #define catName catSig".catalog"
46 CatalogSpeed::TestCreation()
48 for (uint32 i
= 0; i
< kNumStrings
; i
++) {
49 strs
[i
] << "native-string#" << 1000000+i
;
50 ctxs
[i
] << B_TRANSLATION_CONTEXT
;
51 trls
[i
] << "translation#" << 4000000+i
;
54 BStopWatch
watch("catalogSpeed", true);
57 assert(be_locale
!= NULL
);
58 system("mkdir -p ./locale/catalogs/"catSig
);
60 // create an empty catalog of default type...
61 BPrivate::EditableCatalog
cat1("Default", catSig
, "klingon");
62 assert(cat1
.InitCheck() == B_OK
);
64 // ...and populate the catalog with some data:
65 for (uint32 i
= 0; i
< kNumStrings
; i
++) {
66 cat1
.SetString(strs
[i
].String(), trls
[i
].String(), ctxs
[i
].String());
69 printf("\tadded %ld strings in %9Ld usecs\n",
70 cat1
.CountItems(), watch
.ElapsedTime());
74 res
= cat1
.WriteToFile("./locale/catalogs/"catSig
"/klingon.catalog");
77 printf("\t%ld strings written to disk in %9Ld usecs\n",
78 cat1
.CountItems(), watch
.ElapsedTime());
83 CatalogSpeed::TestLookup()
85 BStopWatch
watch("catalogSpeed", true);
87 BCatalog
*cat
= be_catalog
= new BCatalog(catSig
, "klingon");
90 assert(cat
->InitCheck() == B_OK
);
92 printf("\t%ld strings read from disk in %9Ld usecs\n",
93 cat
->CountItems(), watch
.ElapsedTime());
97 for (uint32 i
= 0; i
< kNumStrings
; i
++) {
98 translated
= B_TRANSLATE(strs
[i
].String());
101 printf("\tlooked up %lu strings in %9Ld usecs\n",
102 kNumStrings
, watch
.ElapsedTime());
109 CatalogSpeed::TestIdCreation()
111 BStopWatch
watch("catalogSpeed", true);
116 s
<< "\x01" << typeid(*this).name() << "\x01";
117 //size_t hashVal = __stl_hash_string(s.String());
118 assert(be_locale
!= NULL
);
119 system("mkdir -p ./locale/catalogs/"catSig
);
121 // create an empty catalog of default type...
122 BPrivate::EditableCatalog
cat1("Default", catSig
, "klingon");
123 assert(cat1
.InitCheck() == B_OK
);
125 // ...and populate the catalog with some data:
126 for (uint32 i
= 0; i
< kNumStrings
; i
++) {
127 trls
[i
] = BString("id_translation#") << 6000000+i
;
131 for (uint32 i
= 0; i
< kNumStrings
; i
++) {
132 cat1
.SetString(i
, trls
[i
].String());
135 printf("\tadded %ld strings by id in %9Ld usecs\n",
136 cat1
.CountItems(), watch
.ElapsedTime());
140 res
= cat1
.WriteToFile("./locale/catalogs/"catSig
"/klingon.catalog");
141 assert( res
== B_OK
);
143 printf("\t%ld strings written to disk in %9Ld usecs\n",
144 cat1
.CountItems(), watch
.ElapsedTime());
149 CatalogSpeed::TestIdLookup()
151 BStopWatch
watch("catalogSpeed", true);
153 BCatalog
*cat
= be_catalog
= new BCatalog(catSig
, "klingon");
156 assert(cat
->InitCheck() == B_OK
);
158 printf("\t%ld strings read from disk in %9Ld usecs\n",
159 cat
->CountItems(), watch
.ElapsedTime());
163 for (uint32 i
= 0; i
< kNumStrings
; i
++) {
164 translated
= B_TRANSLATE_ID(i
);
167 printf("\tlooked up %lu strings in %9Ld usecs\n",
168 kNumStrings
, watch
.ElapsedTime());
175 main(int argc
, char **argv
)
177 BApplication
* testApp
178 = new BApplication("application/"catSig
);
180 // change to app-folder:
182 be_app
->GetAppInfo(&appInfo
);
183 BEntry
appEntry(&appInfo
.ref
);
185 appEntry
.GetParent(&appFolder
);
187 appFolder
.GetPath(&appPath
);
188 chdir(appPath
.Path());
190 CatalogSpeed catSpeed
;
191 printf("\t------------------------------------------------\n");
192 printf("\tstring-based catalog usage:\n");
193 printf("\t------------------------------------------------\n");
194 catSpeed
.TestCreation();
195 catSpeed
.TestLookup();
196 printf("\t------------------------------------------------\n");
197 printf("\tid-based catalog usage:\n");
198 printf("\t------------------------------------------------\n");
199 catSpeed
.TestIdCreation();
200 catSpeed
.TestIdLookup();