Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7707101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:16:32+00:00 2026-06-01T00:16:32+00:00

Would anyone please be able to tell me the most efficient way to compare

  • 0

Would anyone please be able to tell me the most efficient way to compare two constant char stars?

#include <iostream>
#include <string>

int main()
{
    const char* value1 = "hello";
    const char* value2 = "HELLO";
    const char* possibility = NULL;


    if(stricmp(value1, value2)==0)
    {
        std::cout <<"\nThey Match!!!!!" << std::endl;
    }
    else{std::cout << "\nThey dont match :("<< std::endl;}

    return 0;
}

I used the following standard function but I know its not the most efficient way to do this?

Besides stricmp cannot handle NULL which in my case has a possibility of occurring.

So is there any other alternatives good for performance?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:16:33+00:00Added an answer on June 1, 2026 at 12:16 am

    There is no efficient way to compare two character strings.

    There are a couple of ways to improve on the basic stricmp(), if it shows up very high on a profile (which I have seen in real apps). You may find that the bulk of the cost is in tolower(), which is a function called on each character to convert it from upper to lowercase before comparison. The overhead of this function call, plus the cost of its body, can add up to significant time, because it must be locale-sensitive and deal with letters like Ö. If you know that your comparisons will only ever be performed in one locale (ie, only in English), then you can speed up tolower() by building a 256-character ASCII lookup table and implementing stricmp() manually.

    With GCC, if you know you are targeting a CPU that supports SSE3, you can also specify the -msse3 command line switch that generates slightly more efficient machine instructions for the string comparison. It mostly helps case sensitive comparison, however.

    In my line of work, any algorithm that requires comparing lots of constant character strings, as opposed to using interns or symbols to represent such identifiers, is considered a code smell. On one project, profiling indicated that about 7% of the CPU time was spent inside tolower() inside stricmp. That is effectively 7 out of 100 machines per data center doing nothing but turning uppercase letters into lowercase ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would anyone be able to tell me how to pull the server name out
Would anyone be able to tell me what I'm doing wrong in the following
Would anyone be able to help me here please. I'm fairly new to VB.net
Would anyone be able to help me with how to get the file properties
Would anyone offer tips, links, code snippets on how to browse to a file
Would anyone like to recommend free alternative to SharePoint Portal ? We want to
Would anyone happen to know a trick that will keep this MSBuild task from
Would anyone know how to test for the appearance of a Toast message on
Would anyone now why this script is disabling my nav in webkit browsers $(document).ready(function
Would anyone one know if Apple has restrictions on providing a user feedback/bug report

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.