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 6189345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:24:08+00:00 2026-05-24T02:24:08+00:00

I was wondering if theres a realy good (performant) solution how to Convert a

  • 0

I was wondering if theres a realy good (performant) solution how to Convert a whole file to lower Case in C.
I use fgetc convert the char to lower case and write it in another temp-file with fputc. At the end i remove the original and rename the tempfile to the old originals name. But i think there must be a better Solution for it.

  • 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-05-24T02:24:09+00:00Added an answer on May 24, 2026 at 2:24 am

    If you’re processing big files (big as in, say, multi-megabytes) and this operation is absolutely speed-critical, then it might make sense to go beyond what you’ve inquired about. One thing to consider in particular is that a character-by-character operation will perform less well than using SIMD instructions.

    I.e. if you’d use SSE2, you could code the toupper_parallel like (pseudocode):

    for (cur_parallel_word = begin_of_block;
         cur_parallel_word < end_of_block;
         cur_parallel_word += parallel_word_width) {
        /*
         * in SSE2, parallel compares are either about 'greater' or 'equal'
         * so '>=' and '<=' have to be constructed. This would use 'PCMPGTB'.
         * The 'ALL' macro is supposed to replicate into all parallel bytes.
         */
        mask1 = parallel_compare_greater_than(*cur_parallel_word, ALL('A' - 1));
        mask2 = parallel_compare_greater_than(ALL('Z'), *cur_parallel_word);
        /*
         * vector op - and all bytes in two vectors, 'PAND'
         */
        mask = mask1 & mask2;
        /*
         * vector op - add a vector of bytes. Would use 'PADDB'.
         */
        new = parallel_add(cur_parallel_word, ALL('a' - 'A'));
        /*
         * vector op - zero bytes in the original vector that will be replaced
         */
        *cur_parallel_word &= !mask;           // that'd become 'PANDN'
        /*
         * vector op - extract characters from new that replace old, then or in.
         */
        *cur_parallel_word |= (new & mask);    // PAND / POR
    }
    

    I.e. you’d use parallel comparisons to check which bytes are uppercase, and then mask both original value and ‘uppercased’ version (one with the mask, the other with the inverse) before you or them together to form the result.

    If you use mmap’ed file access, this could even be performed in-place, saving on the bounce buffer, and saving on many function and/or system calls.

    There is a lot to optimize when your starting point is a character-by-character ‘fgetc’ / ‘fputc’ loop; even shell utilities are highly likely to perform better than that.

    But I agree that if your need is very special-purpose (i.e. something as clear-cut as ASCII input to be converted to uppercase) then a handcrafted loop as above, using vector instruction sets (like SSE intrinsics/assembly, or ARM NEON, or PPC Altivec), is likely to make a significant speedup possible over existing general-purpose utilities.

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

Sidebar

Related Questions

Im just wondering if theres a recommended syntax validator out there anybody can recommend?
I'm using meteor. I'm wondering if theres a shorthand way to do batch updates
Wondering if there is a good way to generate temporary URLs that expire in
I was wondering if there are any general guidelines for when to use regex
Im using Coda, and Im trying to write a program to use Javascript/Jquery to
I was just wondering what language would be a good choice for developing a
I was wondering if there is a good reference to how best to format
I'm relatively new to Lisp, and I was wondering if there really is an
I've been wondering if there is a real advantage to using COMET / push-technologies
Straighforward question really Wondering if there was an application specific for handling coldfusion log

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.