473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

benchmarking linux and C++ program

151 100+
I am benchmarking linux and C++ program to compare the results. I am testing wc -l command and C++ program doing the same but linux command wc -l is much faster than c++ progarm. Why?

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
ifstream in(argv[1]);
char line[1000];
int count =0;
while(in)
{
in.getline(line,1000);
count++;
}
in.close();
cout << count <<endl;
return 0;
}
Jan 26 '10 #1
4 2525
gpraghuram
1,275 Expert 1GB
HI,
The Linux commands will be much more optimized than your code and that may be one of the reason for that.
Thanks
Raghu
Jan 26 '10 #2
Man4ish
151 100+
How can i learn such a great optimization techniques for speeding up my programs.
Jan 26 '10 #3
Man4ish
151 100+
How can i learn such a great optimization techniques for speeding up my programs?
Jan 26 '10 #4
Banfa
9,065 Expert Mod 8TB
You might not be able to but before we go there I have to ask did you compile your program with optomisation preferably speed optomisation. Normally if you compiled it for debug optomisation will be switched off. This would also explain the speed difference.

If you had optomisation on or having switch it on wc still goes faster one of the reasons is that it is likely that wc is making system calls directly. It probably benifits from being able to call the system directly being a part of the system where as your program is using standard C++ and is removed from the system by several layers.

If you still want further information then I suggest that you try looking at the source code for wc and see how they did it. This thread on the Ubuntu forums explains how to get that source code.
Jan 26 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Harry Koh | last post by:
I would like to benchmark some scripts by - measuring the time a page loads - counting the number of connections to MySQL by page - ... So that, i'm looking for a software beside Apache (for...
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
3
by: Andy Dingley | last post by:
I've just started on a new project and inherited a huge pile of XSLT (and I use the term "pile" advisedly !) It runs at glacial speed, and I need to fix this this. Platform is MSXML 4 / ASP ...
8
by: Jerry Coffin | last post by:
As promised, more benchmarking results of comparing C++ to Java. This time around, our first target will be the strcat program. This is one that the C++ version rather bothered me -- I'm...
1
by: Carlo Razzeto | last post by:
Hey there, I have a question about benchmarking. I'm hoping you can help but I'm not sure if this group is dedicated to just standard C++. Here's the question, I have a piece of code I would like...
0
by: Cyrille \cns\ Szymanski | last post by:
Hello, I'm benchmarking .NET IO Completion Ports in C#. For that purpose I've written two basic ECHO servers that I'm testing under high load (over 2.000 clients). IOCP in .Net is fantastic,...
7
by: Wisgary | last post by:
I'm doing some benchmarking tests to compare Microsoft's CLR against Mono's CLR. I could use some suggestions for how to objectively compare the code. To my surprise the few tests I've run so far...
7
by: desktop | last post by:
I have written two different insert functions in a C++ program and would like to test the difference in performance. Can you recommend any benchmarking software for C++ functions that can do...
2
by: chitranjan | last post by:
Hello All, I want to do Bechmarking of PostgreSQL on Linux (fedora) so,please tell me about benchmarking tools of postgresql which is easy to use and implement..It is very urgent for me to do...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.