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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:16:50+00:00 2026-05-29T06:16:50+00:00

I was trying to solve a problem on InterviewStreet. After some time I determine

  • 0

I was trying to solve a problem on InterviewStreet. After some time I determine that I was actually spending the bulk of my time reading the input. This particular question had a lot of input, so that makes some amount of sense. What doesn’t make sense is why the varying methods of input had such different performances:

Initially I had:

std::string command;
std::cin >> command;

Replacing it made it noticeably faster:

char command[5];
cin.ignore();
cin.read(command, 5);

Rewriting everything to use scanf made it even faster

char command;
scanf("get_%c", &command);

All told I cut the time reading the input down by about a 1/3.

I’m wondering there is such a variation in performance between these different methods. Additionally, I’m wondering why using gprof didn’t highlight the time I was spending in I/O, rather seeming to point the blame to my algorithm.

  • 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-29T06:16:52+00:00Added an answer on May 29, 2026 at 6:16 am

    There is a big variation in these routines because console input speed almost never matters.

    And where it does (Unix shell) the code is written in C, reads directly from the stdin device and is efficient.

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

Sidebar

Related Questions

I am trying to solve this problem : https://www.spoj.pl/problems/CERC07S/ I have identified that i
I am trying to solve this problem. I am reading data from csv fiile
I am trying to solve this problem in Haskell but getting time limit exceed.
Trying to solve this problem: I have the following set of divs that when
So I'm trying to solve this problem that asks to look for palindromes in
I'm trying to solve a problem that I outlined in this question . At
since I'm trying to solve this problem for some days, I thought about giving
When trying to solve this problem , I encountered some articles, etc. referring to
Trying to solve this problem . I would like to learn how the bootstrapper
I am trying to solve this problem. I have a series of SELECT statements

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.