L
Razii said:This time I used the new java.nio package for reading and writing.
Result (on my comp) are really pathetic for c++
Also, since the program spends most of the time in reading and
writing the file, I removed sorting from both java and C++ version
(it's irrelevant to IO test anyway).
(for one bible.txt)
Time for reading and writing files: 94 ms (java)
Time for reading and writing files: 78 ms (java)
Time for reading and writing files: 63 ms (java)
Time for reading and writing file: 156 ms (c++)
Time for reading and writing file: 156 ms (c++)
Time for reading and writing file: 156 ms (++)
===== C++ Version =======
#include <ctime>
#include <fstream>
#include <iostream>
int main(int argc,char *argv[])
{
std::ifstream src("bible.txt");
std:fstream dst("output.txt");
clock_t start=clock();
dst << src.rdbuf();
clock_t endt=clock();
std::cout <<"Time for reading and writing file: " <<
double(endt-start)/CLOCKS_PER_SEC * 1000 << " ms\n";
return 0;
}
I've tried with that codes and the results changed a bit:
both programs via the linux "time" command the average
complete execution time was:
dst << src.rdbuf();
If you want do double the speed here, replace the line above with:
while(src.good())
{
char Buffer[1000];
src.read(Buffer, sizeof Buffer);
dst.write(Buffer, src.gcount());
}
For the basic operations carried out in this example code, are you seriously
suggesting that it would be better to have JDK 1.6.x rather than JDK 1.5.x?
I needed to move up from, say, JDK 1.4 to try make _this_ Java program competitive.
Razii said:dst << src.rdbuf();
If you want do double the speed here, replace the line above with:
while(src.good())
{
char Buffer[1000];
src.read(Buffer, sizeof Buffer);
dst.write(Buffer, src.gcount());
}
Yes, it did improve the speed (even doubled for 3 meg file), but for
43 meg file it was still slower than java version.
And for 30x (119 meg) file, I got times like
Time for reading and writing file: 7390 ms (c++)
Time for reading and writing file: 5594 ms (c++)
Time for reading and writing file: 3969 ms (c++)
30x file (119 meg) file with java
Time for reading and writing files: 2219 ms (java)
Time for reading and writing files: 2156 ms (java)
Time for reading and writing files: 2250 ms (java)
Time for reading and writing files: 2453 ms (java)
What's the explanation? There is something wrong somewhere for c++
version.
Yes, obviously the default file buffering is not optimal. Let us "fix"
that:
char Cache[150000000];
int main()
{
std::ifstream src("bible.txt");
std:fstream dst("output.txt");
dst.rdbuf()->pubsetbuf(Cache, sizeof Cache);
clock_t start=clock();
//etc.
Razii said:Since you have a very thin skin, you will always find something that
bothers you and gets under your skin, whether I am here or not. I
suggest you learn the filers that come with your newsreader client.
Add me to ignore and live happy ever after. How about that?
Or, you could learn some manners and find an appropriate group to post
your wisdom into. Otherwise you'll just have to put up with people who
won't ignore your rudeness. For the record, you know nothing about me.
After 30 years in the military, my skin is anything but thin. But you
did make a funny that I will pass on your observation as people who do
know me will find it pretty funny.
#include <ctime>
#include <fstream>
#include <iostream>
char Cache[150000000];
int main(int argc,char *argv[])
{
std::ifstream src("bible3.txt");
std:fstream dst("output.txt");
clock_t start=clock();
dst.rdbuf()->pubsetbuf(Cache, sizeof Cache);
dst << src.rdbuf();
clock_t endt=clock();
std::cout <<"Time for reading and writing file: " <<
double(endt-start)/CLOCKS_PER_SEC * 1000 << " ms\n";
return 0;
}
Or, you could learn some manners and find an appropriate group to post
your wisdom into.
Otherwise you'll just have to put up with people who won't ignore your
rudeness. For the record, you know nothing about me.
my skin is anything but thin.
Razii said:Yes, obviously the default file buffering is not optimal. Let us
"fix" that:
char Cache[150000000];
int main()
{
std::ifstream src("bible.txt");
std:fstream dst("output.txt");
dst.rdbuf()->pubsetbuf(Cache, sizeof Cache);
clock_t start=clock();
//etc.
For 119 meg file, I got times like
C:\>CopyFile
Time for reading and writing file: 3750 ms
C:\>CopyFile
Time for reading and writing file: 3718 ms
C:\>CopyFile
Time for reading and writing file: 3703 ms
C:\>CopyFile
Time for reading and writing file: 3703 ms
C:\>CopyFile
Time for reading and writing file: 3766 ms
for Java it was
Time for reading and writing files: 2219 ms (java)
Time for reading and writing files: 2156 ms (java)
Time for reading and writing files: 2250 ms (java)
Time for reading and writing files: 2453 ms (java)
The compiler options were C:\>cl /O2 CopyFile.cpp
Why the difference?
I used this
#include <ctime>
#include <fstream>
#include <iostream>
char Cache[150000000];
int main(int argc,char *argv[])
{
std::ifstream src("bible3.txt");
std:fstream dst("output.txt");
clock_t start=clock();
dst.rdbuf()->pubsetbuf(Cache, sizeof Cache);
dst << src.rdbuf();
clock_t endt=clock();
std::cout <<"Time for reading and writing file: " <<
double(endt-start)/CLOCKS_PER_SEC * 1000 << " ms\n";
return 0;
}
Is that what you meant?
This makes me curious: Could you elaborate?
Maybe you should seek that information in a group where it's
on topic. People acting like adults don't feed the trolls,
just as they don't tap on fish tanks.
Anyone making a statement that language X is better than Y is
an idiot, no language is always the best. However all
languages have certain characteristics that makes them more
suitable for some purpose than other languages, but in many
cases the best language for a task is the one you know best.
When discussing the merits of different programming languages
I think that comp.programming might be a good place to start.
Asking in a group for a specific language is a sure way to be
told that the language discussed in the group is the best.
* Razii:
Plus, before Java's bignum was reimplemented in pure Java it
was simply a wrapper for GMP (if I recall correctly), so it's
quite silly for a Java programmer/troll to ask whether that
functionality exists in C++.
So its obvious there is some problem with the timing functions because
the c++ program is taking longer than 3 sec but less than 28, after
testing both programs via the linux "time" command the average
complete execution time was:
That gets me about 800 ms on my machine. It turns to 5800 ms if I add
a dst.close() before the final clock() call.
Arved said:Note that I am not discounting the value of keeping up with new versions of
compilers and VMs...feature additions and modifications, bug fixes etc. But
I'd be pretty disappointed if I needed to move up from, say, JDK 1.4 to try
make _this_ Java program competitive.
The whole argument is a troll.
There are advantages to having a
specific functionality as part of the standard (it's always
there, and always in the same fashion), and there are advantages
to having it as a separate third party add on (different
versions can exist, optimized for different uses)
Another discussion can be had concerning what should be part of
the library, and what should be part of the language. Java
suffers with regards to threading, for example, because the
threading is part of the language, and not a third party library
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.