473,657 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Perfomance Considerations

Hi,

What I am having is this -- I got a string start (type is wchar_t) and
the end of a string to compare. Now I've got around 500 words to
compare to and if matched, I want to get an unique integer for the
word. Currently this is done by filling up a std::map<wstrin g, int>
with all words and doing an: iterator it = my_map.find(wch ar_t* value)
and return it->second if found, otherwise return 0. Now this routine
takes pretty much time and I was wondering whether doing a manual list
of

if (strncmp(...) == 0)
...
else if (strncmp(...) == 0)
...

would be faster / more efficient? I was also thinking about doing
something like

switch (*str)
{
case 'a':
if (strncmp(...))
}

i.e. first compaing the first char and then do some deeper evaluation
to avoid calling the strncmp subroutine but I doubt that this even
makes sense.

Any idea so far or any closer description required? Basically as said,
I am having a wchar_t* str_start and an wchar_t* str_end which I want
to compare to predefined words and match an unique integer code for
it.

Regards
Alexander
Nov 20 '07 #1
2 1246
Alexander Adam wrote:
Hi,

What I am having is this -- I got a string start (type is wchar_t) and
the end of a string to compare. Now I've got around 500 words to
compare to and if matched, I want to get an unique integer for the
word. Currently this is done by filling up a std::map<wstrin g, int>
with all words and doing an: iterator it = my_map.find(wch ar_t* value)
and return it->second if found, otherwise return 0. Now this routine
takes pretty much time and I was wondering whether doing a manual list
of

if (strncmp(...) == 0)
..
else if (strncmp(...) == 0)
..

would be faster / more efficient? I was also thinking about doing
something like

switch (*str)
{
case 'a':
if (strncmp(...))
}

i.e. first compaing the first char and then do some deeper evaluation
to avoid calling the strncmp subroutine but I doubt that this even
makes sense.

Any idea so far or any closer description required? Basically as said,
I am having a wchar_t* str_start and an wchar_t* str_end which I want
to compare to predefined words and match an unique integer code for
it.
This looks like a clear case of Hoare's Dictum. Have you even
determined if this is your bottleneck? Have you looked into alternate
datastructures and algorithms? Is there a reason your're using strncmp
instead of wcsncmp (since you're dealing with wchar_t)? Why don't you
convert your wchar_t array to a wstring?

There's lots of stuff to be done up front before you worry about this
sort of micro-optimization.

Nov 20 '07 #2
Alexander Adam wrote:
Hi,

What I am having is this -- I got a string start (type is wchar_t) and
the end of a string to compare. Now I've got around 500 words to
compare to and if matched, I want to get an unique integer for the
word. Currently this is done by filling up a std::map<wstrin g, int>
with all words and doing an: iterator it = my_map.find(wch ar_t* value)
and return it->second if found, otherwise return 0. Now this routine
takes pretty much time and I was wondering whether doing a manual list
of

if (strncmp(...) == 0)
..
else if (strncmp(...) == 0)
..
No, because on average you have to make 250 compares per word, while
std::map does 8 or 9. If some of your search words show up more often
than others then you might sort the compares, but that's not really
helping you.
>
would be faster / more efficient? I was also thinking about doing
something like

switch (*str)
{
case 'a':
if (strncmp(...))
}
Yes that's better. I don't want to bother you with further hints on how
to improve this further, or if you should use hash_maps instead. If
(what I guess from your suggestion to strcmp everything) you have a
*fixed* number of words that you would like to recognize, then a very
good bet is a code generator which turns your wordlist into a piece of
code to recognize these words as fast a possible.
I'm quite happy with re2c (http://re2c.org/), which, with its default
settings, basically does the switch-thing, alas to the bitter end. And
it supports wide-characters.

--
IYesNo yes=YesNoFactor y.getFactoryIns tance().YES;
yes.getDescript ion().equals(ar ray[0].toUpperCase()) ;
Nov 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5093
by: news.onet.pl | last post by:
I've launched some perfomance test for some program measuring number of operations, net messages processed per second, etc. Why is my point, is the question how Java initial and maximal heap is connected with the swap space of Operating System. Those Java utilize both memory and swap space for purpose of its heap? TIA,
2
1650
by: Franco Lombardo | last post by:
I have a table on wich I perfom an indexed search like SELECT * FROM MYTABLE WHERE MYFIELD = ? I'm designing the table and I can decide the type of column MYFIELD. The two choices are: 1) CHAR(14) 2) DECIMAL(14) In which case I will reach the best performances?
2
1053
by: James T. | last post by:
Hello! Let's say I have 2 functions, both return data from the database. Now I would like to compare perfomance of these two functions. I would like to know how long it takes to execute these functions. How can I do that? Thank you! James
0
1023
by: jambalapamba | last post by:
Hi I am removing node from a document depending on the style property and this is taking 7 seconds for checking complete document is there any ideas how can i improve the perfomance. Here is my part of code foreach (IHTMLElement tempElement in document.all) { if (tempElement.style.visibility == "hidden" ) { IHTMLDOMNode node = tempElement as...
4
1548
by: =?Utf-8?B?VmVlcmFiaGFkcmFpYWggTCBN?= | last post by:
Hi, I have two databases D1 with 6 million records and D2 with 95 thousand records. I need to check Common records from these two databases based on UserID and need to insert into other database D3 and also need to create XML files. For this i followed below approach. I have used two threads. -->one thread to Pick the users from D1, filter out against D2 and will be inserting into D3.
3
3248
by: damodharan | last post by:
Hello and thanks in advance. I have two table in DB2 (ver 8). table details are table one(Cust_det) has two fields (Cust_cin and cust_name). table two(cust_add_det) has cust_cin and cust_address fields. To join above two table which sql is better on perfomance point of view? and how conditional where clause works?
2
1150
by: MickJ | last post by:
Hi, I would like to write High perfomance server using C#. It would be desirable to hear offers and advices on this subject.
4
1181
by: Alexander Adam | last post by:
Hi! I've got a pretty complex data structure that keeps instances of structs allocated with the new operator. Now my issue is that those structures are required to be allocated / deallocated pretty often resulting in a huge perfomance issue. Usually what I am doing is to create arrays and initialize their sizes a few times bigger than originally required to avoid another allocation on the next run. Then I do simply reset them
1
1763
by: Henri.Chinasque | last post by:
Hi all, I've been considering that my objects should subscribe to an event via a weak reference, however I've found several warnings that this approach comes with concurrency considerations, like the fact that the event handler method on the subscriber could be called and be executing while the object is being garbage collected. Not being super strong in the multithreaded department, I am having a hard time coming up with other...
0
1189
by: ferozanna | last post by:
I am using Asp.net 1.3 with C# My application used by call center people My applicaton is a three tier arch I have create data layer as class ibrary which goint to talke Ssqlserver 205 db At time 2000 to 3000 user are using How can i improve my application perfomance, Give me tips
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.