Google Groups Home
Help | Sign in
<Performance> Simple C/C++ Perfometer: Copying Files (Versions 4.x)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
Alex Vinokur  
View profile
 More options Mar 23 2005, 12:39 am
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Wed, 23 Mar 2005 07:39:04 +0200
Local: Wed, Mar 23 2005 12:39 am
Subject: <Performance> Simple C/C++ Perfometer: Copying Files (Versions 4.x)

#####################
### Program files ###
#####################

=========================================
* Performance
* Comparative Performance Measurement
-----------------------------------------
* Tool     : Simple C/C++ Perfometer
* Algorithm: Copying files
* Language : C++
* Content  : Program files
* Version  : F2F-4.0
-----------------------------------------
* Attachments
  - file2file-4-0.cpp
=========================================

  Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

  file2file-4-0.cpp
63K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Vinokur  
View profile
 More options Apr 14 2006, 12:57 pm
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Fri, 14 Apr 2006 19:57:17 +0300
Local: Fri, Apr 14 2006 12:57 pm
Subject: Re: <Performance> Simple C/C++ Perfometer: Copying Files (Versions 4.x)

=========================================
* Performance
* Comparative Performance Measurement
-----------------------------------------
* Tool     : Simple C/C++ Perfometer
* Algorithm: Copying files
* Language : C++
* Content  : Program files
* Version  : F2F-4.0.1
-----------------------------------------
* Attachments
  - file2file-4-0.1.cpp
=========================================

  Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ file2file-4-0-1.cpp ]
// =========================================================================== //
//  C/C++ Program Performance Measurement
    #define PROGRAM_NAME     "Simple C/C++ Perfometer : Copying files"
    #define PROGRAM_VERSION  "Version F2F-4.0.1"
//
//  -------------------------------------
//
//  Copyright (C) 2002-2006 Alex Vinokur
//
//  --------------------------------------------------------------------------
//
//  This software is provided 'as-is', without any express or implied
//  warranty.  In no event will the author be held liable for any damages
//  arising from the use of this software.
//
//  Permission is granted to anyone to use this software for any purpose,
//  including commercial applications, and to alter it and redistribute it
//  freely, subject to the following restrictions:
//
//  1. The origin of this software must not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgment in the product documentation would be
//     appreciated but is not required.
//  2. Altered source versions must be plainly marked as such, and must not be
//     misrepresented as being the original software.
//  3. This notice may not be removed or altered from any source distribution.
//
//     Alex Vinokur
//    
//  --------------------------------------------------------------------------
//
//  email:alex DOT vinokur AT gmail DOT com
//  http://up.to/alexv
//
// ===========================================================================

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
//    Testsuites
//    ----------
//    C-01      : C-Functions getc() and putc()
//    C-02      : C-Functions fgetc() and fputc()
//    C-03      : C-Functions fread() and fwrite() - with const size buffer
//    C-04      : C-Functions fread() and fwrite() - with max size buffer
//    unix_C_05 : UNIX system call mmap
//    CPP-01    : istream::operator>> and ostream::operator<<
//    CPP-02    : streambuf::sbumpc() and streambuf::sputc()
//    CPP-03    : streambuf::sbumpc() and ostream::operator<<
//    CPP-04    : ifstream::rdbuf() and ostream::operator<<
//    CPP-05    : istream::read() and ostream::write() - with const size buffer
//    CPP-06    : istream::read() and ostream::write(), std::ostringstream, ostream::operator<< - with const buffer
//    CPP-07    : istream::readsome() and ostream::write() - with const size buffer
//    CPP-08    : istream::read() and ostream::write() - with max size buffer
//    CPP-09    : std::getline, std::ostringstream, ostream::operator<<
//    CPP-10    : std::getline, std::string, ostream::operator<<
//    CPP-11    : istream::getline, std::ostringstream, ostream::operator<<
//    CPP-12    : istream::get(char) and ostream::put
//    CPP-13    : istream::get(char)
//    CPP-14    : istream::get(char*, streamsize) , ostream::operator<< - with const size buffer
//    CPP-15    : istream::get(streambuf&)  and std::streambuf, ostream::operator<<
//    CPP-16    : std::istream_iterator, std::ostream_iterator and std::copy
//    CPP-17    : std::istream_iterator, std::string
//    CPP-18    : std::istreambuf_iterator, std::ostreambuf_iterator and std::copy
//    CPP-19    : std::istreambuf_iterator, std::ostreambuf_iterator and std::transform
//    CPP-20    : std::istreambuf_iterator and std::string
//    CPP-21    : std::vector and std::copy
//    CPP-22    : std::vector and push_back()
//    CPP-23    : std::vector and istream::read()
//    CPP-24    : std::string and istream::read()
//
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// --------------------------------------
#if ((defined unix) || (defined __unix) || (defined unix__) || (defined __unix__))
#if (!((defined DJGPP) || (defined __DJGPP) || (defined DJGPP__) || (defined __DJGPP__)))
#define UNIX_ENV
#endif
#endif

// ==============
#include <ctime>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <iterator>
#include <algorithm>
#ifdef UNIX_ENV
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#endif
using namespace std;

// --------------------------------------
typedef unsigned long ulong;
typedef unsigned int  uint;

// --------------------------------------
#define  MAX_VALUE(x,y)  ((x) > (y) ? (x) : (y))

#define  ASSERT(x)       if (!(x)) \
                         { \
                         assert(x); \
                         cerr << "[" \
                              << __FILE__ \
                              << ", " \
                              << __LINE__  \
                              << "] assert() not working" \
                              << endl;  \
                              abort(); \
                         }

// ========================================
// ====== Part-1: Common Auxilary Functions
// ========================================

// ------------------------------
// Function 1.01
static string get_compiler_info()
// ------------------------------
{
ostringstream oss;
ostringstream tss;
string str;

// ------ GNU gcc ------
#ifdef __GNUC__
  oss.str("");
  tss.str("");
  str.erase();

  oss << "GNU gcc " << __GNUC__;
#ifdef __GNUC_MINOR__
  oss << "." << __GNUC_MINOR__;
#ifdef __GNUC_PATCHLEVEL__
#if (__GNUC_PATCHLEVEL__)
  oss << "." << __GNUC_PATCHLEVEL__;
#endif
#endif
#endif

#if (__CYGWIN32__ || __CYGWIN__)
  oss << " (CYGWIN)";
#endif

#if (__MINGW32__ || __MINGW__ )
  oss << " (MINGW)";
#endif

#if (__DJGPP__)
  oss << " (DGGPP " << __DJGPP__;
#ifdef __DJGPP_MINOR__
  oss << "." << __DJGPP_MINOR__;
#endif
  oss << ")";
#endif

#endif

// ------ Microsoft C++ ------
#ifdef _MSC_VER
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Microsoft C++ ";
  tss << _MSC_VER;
  str = tss.str();
  ASSERT (str.size() == 4);
  oss << str[0] << str[1] << "." << str[2] << str[3];

#ifdef _MANAGED

#if (_MANAGED)
  oss << " (Managed)";
#else
  ASSERT (0);
  oss << " (Unmanaged)";
#endif
#else

  oss << " (Unmanaged)";
#endif

#endif

// ------ Intel C++ ------
#ifdef __INTEL_COMPILER
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Intel C++ ";
  tss << __INTEL_COMPILER;
  str = tss.str();
  ASSERT (str.size() == 3);
  oss << str[0] << "." << str[1];
#endif

// ------ Borland C++ ------
#ifdef __BCPLUSPLUS__
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Borland C++ ";
  tss << hex << __BCPLUSPLUS__;
  str = tss.str();
  ASSERT (str.size() == 3);
  oss << str[0] << "." << str[1] << "." << str[2];
#endif

// ------ Digital Mars C++ ------
#ifdef __DMC__
  oss.str("");
  tss.str("");
  str.erase();

#ifndef __DMC_VERSION_STRING__
#error __DMC_VERSION_STRING__ Not Defined
#endif
  oss << __DMC_VERSION_STRING__;
#endif

  return oss.str();

} // get_compiler_info

// -----------------------------
// Function 1.02
static void show_compiler_info()
// -----------------------------
{
const string str(get_compiler_info());

  if (str.empty()) return;

  cout << string (str.size(), '-') << endl;
  cout << str << endl;
  cout << string (str.size(), '-') << endl;

}

// -----------------------------------------
// Function 1.03
static size_t get_filesize_via_fseek_ftell (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
FILE* fp = NULL;

  fp = fopen(filename_i, is_txt_mode_i ? "r" : "rb");
  ASSERT (fp);

int rc = fseek(fp, 0, SEEK_END);
  ASSERT (rc == 0);

const size_t ret_filesize (ftell(fp));

  rc = fclose(fp);
  ASSERT (rc == 0);

  return ret_filesize;

}

#ifdef UNIX_ENV

// -----------------------------------------
// Function 1.04
static size_t get_filesize_via_lseek (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
{
// -----------------------------------------
int fd = -1;

  fd = open(filename_i, is_txt_mode_i ? O_RDONLY : O_RDONLY | O_BINARY);
  ASSERT (fd != -1);

off_t rc;
  rc = lseek(fd, 0, SEEK_END);
  ASSERT (rc != -1);

const size_t ret_filesize (static_cast<size_t>(rc));

  rc = close(fd);
  ASSERT (rc == 0);

  return ret_filesize;

}

// -----------------------------------------
// Function 1.05
static size_t get_filesize_via_fstat (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
int fd = -1;

  fd = open(filename_i, is_txt_mode_i ? O_RDONLY : O_RDONLY | O_BINARY);
  ASSERT (fd != -1);

struct stat buf;
int rc = fstat(fd, &buf);
  ASSERT (rc == 0);

const size_t ret_filesize (static_cast<size_t>(buf.st_size));

  rc = close(fd);
  ASSERT (rc == 0);

  return ret_filesize;

}

// -----------------------------------------
// Function 1.06
static size_t get_filesize_via_stat (
        const char * const filename_i
        )
// -----------------------------------------
{
struct stat buf;

int rc = stat (filename_i, &buf);
  ASSERT (rc == 0);

const size_t ret_filesize (static_cast<size_t>(buf.st_size));

  return ret_filesize;

}

#endif

// -----------------------------------------
// Function 1.07
static size_t get_filesize_via_seekg_tellg (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
ifstream fs;

  if (is_txt_mode_i) fs.open (filename_i);
  else               fs.open (filename_i, ios::binary);

  ASSERT (fs);
  ASSERT (fs.is_open());

   fs.seekg(0, ios::beg);
const ios::pos_type start_pos = fs.tellg();

   fs.seekg(0, ios::end);
const ios::pos_type end_pos = fs.tellg();

const size_t ret_filesize (static_cast<size_t>(end_pos - start_pos));

  fs.close();
  ASSERT (!fs.is_open());

  return ret_filesize;

}

// -----------------------------------------
// Function 1.08
static size_t get_filesize_via_distance (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
ifstream fs;

  if (is_txt_mode_i) fs.open (filename_i);
  else               fs.open (filename_i, ios::binary);

  ASSERT (fs);
  ASSERT (fs.is_open());

const size_t ret_filesize (static_cast<size_t>(distance(
        istreambuf_iterator<char>(fs),
        istreambuf_iterator<char>()
        )));
...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Vinokur  
View profile
 More options Oct 15 2006, 1:10 pm
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Sun, 15 Oct 2006 19:10:20 +0200
Local: Sun, Oct 15 2006 1:10 pm
Subject: <Performance> Simple C/C++ Perfometer: Copying Files (Versions 4.x)

#####################
### Program files ###
#####################

=========================================
* Performance
* Comparative Performance Measurement
-----------------------------------------
* Tool     : Simple C/C++ Perfometer
* Algorithm: Copying files
* Language : C++
* Content  : Program files
* Version  : F2F-4.1
-----------------------------------------
* Attachments
  - file2file-4-1.cpp
=========================================

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ file2file-4-1.cpp ]
// =========================================================================== //
//  C/C++ Program Performance Measurement
    #define PROGRAM_NAME     "Simple C/C++ Perfometer : Copying files"
    #define PROGRAM_VERSION  "Version F2F-4.1"
//
//  -------------------------------------
//
//  Copyright (C) 2002-2006 Alex Vinokur
//
//  --------------------------------------------------------------------------
//
//  This software is provided 'as-is', without any express or implied
//  warranty.  In no event will the author be held liable for any damages
//  arising from the use of this software.
//
//  Permission is granted to anyone to use this software for any purpose,
//  including commercial applications, and to alter it and redistribute it
//  freely, subject to the following restrictions:
//
//  1. The origin of this software must not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgment in the product documentation would be
//     appreciated but is not required.
//  2. Altered source versions must be plainly marked as such, and must not be
//     misrepresented as being the original software.
//  3. This notice may not be removed or altered from any source distribution.
//
//     Alex Vinokur
//    
//  --------------------------------------------------------------------------
//
//  email:alex DOT vinokur AT gmail DOT com
//  http://up.to/alexv
//
// ===========================================================================

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
//    Testsuites
//    ----------
//    C-01      : C-Functions getc() and putc()
//    C-02      : C-Functions fgetc() and fputc()
//    C-03      : C-Functions fread() and fwrite() - with const size buffer
//    C-04      : C-Functions fread() and fwrite() - with max size buffer
//    C-05      : C-Functions fgets() and fputs()  - with max size buffer
//    Unix-C-06 : UNIX system call mmap
//    CPP-01    : istream::operator>> and ostream::operator<<
//    CPP-02    : streambuf::sbumpc() and streambuf::sputc()
//    CPP-03    : streambuf::sbumpc() and ostream::operator<<
//    CPP-04    : ifstream::rdbuf() and ostream::operator<<
//    CPP-05    : istream::read() and ostream::write() - with const size buffer
//    CPP-06    : istream::read() and ostream::write(), std::ostringstream, ostream::operator<< - with const buffer
//    CPP-07    : istream::readsome() and ostream::write() - with const size buffer
//    CPP-08    : istream::read() and ostream::write() - with max size buffer
//    CPP-09    : std::getline, std::ostringstream, ostream::operator<<
//    CPP-10    : std::getline, std::string, ostream::operator<<
//    CPP-11    : istream::getline, std::ostringstream, ostream::operator<<
//    CPP-12    : istream::get(char) and ostream::put
//    CPP-13    : istream::get(char)
//    CPP-14    : istream::get(char*, streamsize) , ostream::operator<< - with const size buffer
//    CPP-15    : istream::get(streambuf&)  and std::streambuf, ostream::operator<<
//    CPP-16    : std::istream_iterator, std::ostream_iterator and std::copy
//    CPP-17    : std::istream_iterator, std::string
//    CPP-18    : std::istreambuf_iterator, std::ostreambuf_iterator and std::copy
//    CPP-19    : std::istreambuf_iterator, std::ostreambuf_iterator and std::transform
//    CPP-20    : std::istreambuf_iterator and std::string
//    CPP-21    : std::vector and std::copy
//    CPP-22    : std::vector and push_back()
//    CPP-23    : std::vector and istream::read()
//    CPP-24    : std::string and istream::read()
//
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// --------------------------------------
#if ((defined unix) || (defined __unix) || (defined unix__) || (defined __unix__))
#if (!((defined DJGPP) || (defined __DJGPP) || (defined DJGPP__) || (defined __DJGPP__)))
#define UNIX_ENV
#endif
#endif

// ==============
#include <ctime>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <iterator>
#include <algorithm>
#ifdef UNIX_ENV
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#endif
using namespace std;

// --------------------------------------
typedef unsigned long ulong;
typedef unsigned int  uint;

// --------------------------------------
#define  MAX_VALUE(x,y)  ((x) > (y) ? (x) : (y))

#define  ASSERT(x)       if (!(x)) \
                         { \
                         assert(x); \
                         cerr << "[" \
                              << __FILE__ \
                              << ", " \
                              << __LINE__  \
                              << "] assert() not working" \
                              << endl;  \
                              abort(); \
                         }

// ========================================
// ====== Part-1: Common Auxilary Functions
// ========================================

// ------------------------------
// Function 1.01
static string get_compiler_info()
// ------------------------------
{
ostringstream oss;
ostringstream tss;
string str;

// ------ GNU gcc ------
#ifdef __GNUC__
  oss.str("");
  tss.str("");
  str.erase();

  oss << "GNU gcc " << __GNUC__;
#ifdef __GNUC_MINOR__
  oss << "." << __GNUC_MINOR__;
#ifdef __GNUC_PATCHLEVEL__
#if (__GNUC_PATCHLEVEL__)
  oss << "." << __GNUC_PATCHLEVEL__;
#endif
#endif
#endif

#if (__CYGWIN32__ || __CYGWIN__)
  oss << " (CYGWIN)";
#endif

#if (__MINGW32__ || __MINGW__ )
  oss << " (MINGW)";
#endif

#if (__DJGPP__)
  oss << " (DJGPP " << __DJGPP__;
#ifdef __DJGPP_MINOR__
  oss << "." << __DJGPP_MINOR__;
#endif
  oss << ")";
#endif

#endif

// ------ Microsoft C++ ------
#ifdef _MSC_VER
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Microsoft C++ ";
  tss << _MSC_VER;
  str = tss.str();
  ASSERT (str.size() == 4);
  oss << str[0] << str[1] << "." << str[2] << str[3];

#ifdef _MANAGED

#if (_MANAGED)
  oss << " (Managed)";
#else
  ASSERT (0);
  oss << " (Unmanaged)";
#endif
#else

  oss << " (Unmanaged)";
#endif

#endif

// ------ Intel C++ ------
#ifdef __INTEL_COMPILER
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Intel C++ ";
  tss << __INTEL_COMPILER;
  str = tss.str();
  ASSERT (str.size() == 3);
  oss << str[0] << "." << str[1];
#endif

// ------ Borland C++ ------
#ifdef __BCPLUSPLUS__
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Borland C++ ";
  tss << hex << __BCPLUSPLUS__;
  str = tss.str();
  ASSERT (str.size() == 3);
  oss << str[0] << "." << str[1] << "." << str[2];
#endif

// ------ Digital Mars C++ ------
#ifdef __DMC__
  oss.str("");
  tss.str("");
  str.erase();

#ifndef __DMC_VERSION_STRING__
#error __DMC_VERSION_STRING__ Not Defined
#endif
  oss << __DMC_VERSION_STRING__;
#endif

  return oss.str();

} // get_compiler_info

// -----------------------------
// Function 1.02
static void show_compiler_info()
// -----------------------------
{
const string str(get_compiler_info());

  if (str.empty()) return;

  cout << string (str.size(), '-') << endl;
  cout << str << endl;
  cout << string (str.size(), '-') << endl;

}

// -----------------------------------------
// Function 1.03
static size_t get_filesize_via_fseek_ftell (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
FILE* fp = NULL;

  fp = fopen(filename_i, is_txt_mode_i ? "r" : "rb");
  ASSERT (fp);

int rc = fseek(fp, 0, SEEK_END);
  ASSERT (rc == 0);

const size_t ret_filesize (ftell(fp));

  rc = fclose(fp);
  ASSERT (rc == 0);

  return ret_filesize;

}

#ifdef UNIX_ENV

// -----------------------------------------
// Function 1.04
static size_t get_filesize_via_lseek (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
{
// -----------------------------------------
int fd = -1;

  fd = open(filename_i, is_txt_mode_i ? O_RDONLY : O_RDONLY | O_BINARY);
  ASSERT (fd != -1);

off_t rc;
  rc = lseek(fd, 0, SEEK_END);
  ASSERT (rc != -1);

const size_t ret_filesize (static_cast<size_t>(rc));

  rc = close(fd);
  ASSERT (rc == 0);

  return ret_filesize;

}

// -----------------------------------------
// Function 1.05
static size_t get_filesize_via_fstat (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
int fd = -1;

  fd = open(filename_i, is_txt_mode_i ? O_RDONLY : O_RDONLY | O_BINARY);
  ASSERT (fd != -1);

struct stat buf;
int rc = fstat(fd, &buf);
  ASSERT (rc == 0);

const size_t ret_filesize (static_cast<size_t>(buf.st_size));

  rc = close(fd);
  ASSERT (rc == 0);

  return ret_filesize;

}

// -----------------------------------------
// Function 1.06
static size_t get_filesize_via_stat (
        const char * const filename_i
        )
// -----------------------------------------
{
struct stat buf;

int rc = stat (filename_i, &buf);
  ASSERT (rc == 0);

const size_t ret_filesize (static_cast<size_t>(buf.st_size));

  return ret_filesize;

}

#endif

// -----------------------------------------
// Function 1.07
static size_t get_filesize_via_seekg_tellg (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
ifstream fs;

  if (is_txt_mode_i) fs.open (filename_i);
  else               fs.open (filename_i, ios::binary);

  ASSERT (fs);
  ASSERT (fs.is_open());

   fs.seekg(0, ios::beg);
const ios::pos_type start_pos = fs.tellg();

   fs.seekg(0, ios::end);
const ios::pos_type end_pos = fs.tellg();

const size_t ret_filesize (static_cast<size_t>(end_pos - start_pos));

  fs.close();
  ASSERT (!fs.is_open());

  return ret_filesize;

}

// -----------------------------------------
// Function 1.08
static size_t get_filesize_via_distance (
        const char * const filename_i,
        const bool         is_txt_mode_i
        )
// -----------------------------------------
{
ifstream fs;

  if (is_txt_mode_i) fs.open (filename_i);
  else               fs.open (filename_i, ios::binary);

  ASSERT (fs);
  ASSERT (fs.is_open());

const size_t ret_filesize ...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Vinokur  
View profile
 More options Oct 22 2006, 12:46 pm
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Sun, 22 Oct 2006 18:46:59 +0200
Local: Sun, Oct 22 2006 12:46 pm
Subject: <Performance> Simple C/C++ Perfometer: Copying Files (Versions 4.x)

#####################
### Program files ###
#####################

=========================================
* Performance
* Comparative Performance Measurement
-----------------------------------------
* Tool     : Simple C/C++ Perfometer
* Algorithm: Copying files
* Language : C++
* Content  : Program files
* Version  : F2F-4.1.1
-----------------------------------------
* Attachments
  - file2file-4-1-1.cpp
=========================================

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ file2file-4-1-1.cpp ]
// =========================================================================== //
//  C/C++ Program Performance Measurement
    #define PROGRAM_NAME     "Simple C/C++ Perfometer : Copying files"
    #define PROGRAM_VERSION  "Version F2F-4.1.1"
//
//  -------------------------------------
//
//  Copyright (C) 2002-2006 Alex Vinokur
//
//  --------------------------------------------------------------------------
//
//  This software is provided 'as-is', without any express or implied
//  warranty.  In no event will the author be held liable for any damages
//  arising from the use of this software.
//
//  Permission is granted to anyone to use this software for any purpose,
//  including commercial applications, and to alter it and redistribute it
//  freely, subject to the following restrictions:
//
//  1. The origin of this software must not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgment in the product documentation would be
//     appreciated but is not required.
//  2. Altered source versions must be plainly marked as such, and must not be
//     misrepresented as being the original software.
//  3. This notice may not be removed or altered from any source distribution.
//
//     Alex Vinokur
//    
//  --------------------------------------------------------------------------
//
//  email:alex DOT vinokur AT gmail DOT com
//  http://up.to/alexv
//
// ===========================================================================

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
//    Testsuites
//    ----------
//    C-01      : C-Functions getc() and putc()
//    C-02      : C-Functions fgetc() and fputc()
//    C-03      : C-Functions fgets() and fputs()  - with const size buffer
//    C-04      : C-Functions fgets() and fputs()  - with max size buffer
//    C-05      : C-Functions fread() and fwrite() - with const size buffer
//    C-06      : C-Functions fread() and fwrite() - with max size buffer
//    Unix-C-07 : UNIX system call mmap
//    CPP-01    : istream::operator>> and ostream::operator<<
//    CPP-02    : streambuf::sbumpc() and streambuf::sputc()
//    CPP-03    : streambuf::sbumpc() and ostream::operator<<
//    CPP-04    : ifstream::rdbuf() and ostream::operator<<
//    CPP-05    : istream::read() and ostream::write() - with const size buffer
//    CPP-06    : istream::read() and ostream::write(), std::ostringstream, ostream::operator<< - with const buffer
//    CPP-07    : istream::readsome() and ostream::write() - with const size buffer
//    CPP-08    : istream::read() and ostream::write() - with max size buffer
//    CPP-09    : std::getline, std::ostringstream, ostream::operator<<
//    CPP-10    : std::getline, std::string, ostream::operator<<
//    CPP-11    : istream::getline, std::ostringstream, ostream::operator<<
//    CPP-12    : istream::get(char) and ostream::put
//    CPP-13    : istream::get(char)
//    CPP-14    : istream::get(char*, streamsize) , ostream::operator<< - with const size buffer
//    CPP-15    : istream::get(streambuf&)  and std::streambuf, ostream::operator<<
//    CPP-16    : std::istream_iterator, std::ostream_iterator and std::copy
//    CPP-17    : std::istream_iterator, std::string
//    CPP-18    : std::istreambuf_iterator, std::ostreambuf_iterator and std::copy
//    CPP-19    : std::istreambuf_iterator, std::ostreambuf_iterator and std::transform
//    CPP-20    : std::istreambuf_iterator and std::string
//    CPP-21    : std::vector and std::copy
//    CPP-22    : std::vector and push_back()
//    CPP-23    : std::vector and istream::read()
//    CPP-24    : std::string and istream::read()
//
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// --------------------------------------
#if ((defined unix) || (defined __unix) || (defined unix__) || (defined __unix__))
#if (!((defined DJGPP) || (defined __DJGPP) || (defined DJGPP__) || (defined __DJGPP__)))
#define UNIX_ENV
#endif
#endif

// ==============
#include <ctime>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <iterator>
#include <algorithm>
#ifdef UNIX_ENV
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#endif
using namespace std;

// --------------------------------------
typedef unsigned long ulong;
typedef unsigned int  uint;

// --------------------------------------
#define  MAX_VALUE(x,y)  ((x) > (y) ? (x) : (y))

#define  ASSERT(x)       if (!(x)) \
    { \
    assert(x); \
    cerr << "[" \
         << __FILE__ \
         << ", " \
         << __LINE__  \
         << "] assert() not working" \
         << endl;  \
         abort(); \
    }

// ========================================
// ====== Part-1: Common Auxilary Functions
// ========================================

// ------------------------------
// Function 1.01
static string get_compiler_info()
// ------------------------------
{
ostringstream oss;
ostringstream tss;
string str;

// ------ GNU gcc ------
#ifdef __GNUC__
  oss.str("");
  tss.str("");
  str.erase();

  oss << "GNU gcc " << __GNUC__;
#ifdef __GNUC_MINOR__
  oss << "." << __GNUC_MINOR__;
#ifdef __GNUC_PATCHLEVEL__
#if (__GNUC_PATCHLEVEL__)
  oss << "." << __GNUC_PATCHLEVEL__;
#endif
#endif
#endif

#if (__CYGWIN32__ || __CYGWIN__)
  oss << " (CYGWIN)";
#endif

#if (__MINGW32__ || __MINGW__ )
  oss << " (MINGW)";
#endif

#if (__DJGPP__)
  oss << " (DJGPP " << __DJGPP__;
#ifdef __DJGPP_MINOR__
  oss << "." << __DJGPP_MINOR__;
#endif
  oss << ")";
#endif

#endif

// ------ Microsoft C++ ------
#ifdef _MSC_VER
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Microsoft C++ ";
  tss << _MSC_VER;
  str = tss.str();
  ASSERT (str.size() == 4);
  oss << str[0] << str[1] << "." << str[2] << str[3];

#ifdef _MANAGED

#if (_MANAGED)
  oss << " (Managed)";
#else
  ASSERT (0);
  oss << " (Unmanaged)";
#endif
#else

  oss << " (Unmanaged)";
#endif

#endif

// ------ Intel C++ ------
#ifdef __INTEL_COMPILER
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Intel C++ ";
  tss << __INTEL_COMPILER;
  str = tss.str();
  ASSERT (str.size() == 3);
  oss << str[0] << "." << str[1];
#endif

// ------ Borland C++ ------
#ifdef __BCPLUSPLUS__
  oss.str("");
  tss.str("");
  str.erase();

  oss << "Borland C++ ";
  tss << hex << __BCPLUSPLUS__;
  str = tss.str();
  ASSERT (str.size() == 3);
  oss << str[0] << "." << str[1] << "." << str[2];
#endif

// ------ Digital Mars C++ ------
#ifdef __DMC__
  oss.str("");
  tss.str("");
  str.erase();

#ifndef __DMC_VERSION_STRING__
#error __DMC_VERSION_STRING__ Not Defined
#endif
  oss << __DMC_VERSION_STRING__;
#endif

  return oss.str();

} // get_compiler_info

// -----------------------------
// Function 1.02
static void show_compiler_info()
// -----------------------------
{
const string str(get_compiler_info());

  if (str.empty()) return;

  cout << string (str.size(), '-') << endl;
  cout << str << endl;
  cout << string (str.size(), '-') << endl;

}

// -----------------------------------------
// Function 1.03
static size_t get_filesize_via_fseek_ftell (
 const char * const filename_i,
 const bool         is_txt_mode_i
 )
// -----------------------------------------
{
FILE* fp = NULL;

  fp = fopen(filename_i, is_txt_mode_i ? "r" : "rb");
  ASSERT (fp);

int rc = fseek(fp, 0, SEEK_END);
  ASSERT (rc == 0);

const size_t ret_filesize (ftell(fp));

  rc = fclose(fp);
  ASSERT (rc == 0);

  return ret_filesize;

}

#ifdef UNIX_ENV

// -----------------------------------------
// Function 1.04
static size_t get_filesize_via_lseek (
 const char * const filename_i,
 const bool         is_txt_mode_i
 )
{
// -----------------------------------------
int fd = -1;

  fd = open(filename_i, is_txt_mode_i ? O_RDONLY : O_RDONLY | O_BINARY);
  ASSERT (fd != -1);

off_t rc;
  rc = lseek(fd, 0, SEEK_END);
  ASSERT (rc != -1);

const size_t ret_filesize (static_cast<size_t>(rc));

  rc = close(fd);
  ASSERT (rc == 0);

  return ret_filesize;

}

// -----------------------------------------
// Function 1.05
static size_t get_filesize_via_fstat (
 const char * const filename_i,
 const bool         is_txt_mode_i
 )
// -----------------------------------------
{
int fd = -1;

  fd = open(filename_i, is_txt_mode_i ? O_RDONLY : O_RDONLY | O_BINARY);
  ASSERT (fd != -1);

struct stat buf;
int rc = fstat(fd, &buf);
  ASSERT (rc == 0);

const size_t ret_filesize (static_cast<size_t>(buf.st_size));

  rc = close(fd);
  ASSERT (rc == 0);

  return ret_filesize;

}

// -----------------------------------------
// Function 1.06
static size_t get_filesize_via_stat (
 const char * const filename_i
 )
// -----------------------------------------
{
struct stat buf;

int rc = stat (filename_i, &buf);
  ASSERT (rc == 0);

const size_t ret_filesize (static_cast<size_t>(buf.st_size));

  return ret_filesize;

}

#endif

// -----------------------------------------
// Function 1.07
static size_t get_filesize_via_seekg_tellg (
 const char * const filename_i,
 const bool         is_txt_mode_i
 )
// -----------------------------------------
{
ifstream fs;

  if (is_txt_mode_i) fs.open (filename_i);
  else               fs.open (filename_i, ios::binary);

  ASSERT (fs);
  ASSERT (fs.is_open());

   fs.seekg(0, ios::beg);
const ios::pos_type start_pos = fs.tellg();

   fs.seekg(0, ios::end);
const ios::pos_type end_pos = fs.tellg();

const size_t ret_filesize (static_cast<size_t>(end_pos - start_pos));

  fs.close();
  ASSERT (!fs.is_open());

  return ret_filesize;

}

// -----------------------------------------
// Function 1.08
static size_t get_filesize_via_distance (
 const char * const filename_i,
 const bool         is_txt_mode_i
 )
// -----------------------------------------
{
ifstream fs;

  if (is_txt_mode_i) fs.open (filename_i);
  else               fs.open (filename_i, ios::binary);

  ASSERT (fs);
...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google