動作環境
C++ Builder XE4
関連: https://qiita.com/7of9/items/376f0e7664216de224db
上記のスクリプトを一部修正して、ダミーファイルを作成した。
900個のファイル。175MB。
このファイルをコピーする実装を試した。
Unit1.h
//---------------------------------------------------------------------------
# ifndef Unit1H
# define Unit1H
//---------------------------------------------------------------------------
# include <System.Classes.hpp>
# include <Vcl.Controls.hpp>
# include <Vcl.StdCtrls.hpp>
# include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE で管理されるコンポーネント
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // ユーザー宣言
public: // ユーザー宣言
void __fastcall CopyFolder(String dstDir);
void __fastcall CopyFiles(String dstDir);
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
# endif
Unit1.cpp
//---------------------------------------------------------------------------
# include <vcl.h>
# pragma hdrstop
# include <IOUtils.hpp>
# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
/*
v0.1 2017/10/13
- add CopyFiles()
- add CopyFolder()
*/
static const String kBaseDir = L"D:\\WORK\\data_171013";
static String srcDir = kBaseDir + "\\src";
void __fastcall TForm1::CopyFolder(String dstDir)
{
DWORD start = GetTickCount();
TDirectory::Copy(srcDir, dstDir);
DWORD elapsed = GetTickCount() - start;
}
void __fastcall TForm1::CopyFiles(String dstDir)
{
String prefix[] = {
L"600K",
L"200",
L"100"
};
DWORD start = GetTickCount();
int len_prf = sizeof(prefix)/sizeof(prefix[0]);
for(int pi=0; pi<len_prf; pi++) { // pi: prefix index
for (int idx=1; idx <= 300; idx++) {
String wrk = String().sprintf(L"%05d", idx);
String fn = prefix[pi] + L"_" + wrk + L".dat";
TFile::Copy(srcDir + L"\\" + fn, dstDir + L"\\" + fn);
}
}
DWORD elapsed = GetTickCount() - start;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CopyFolder(kBaseDir + L"\\dst1");
CopyFiles(kBaseDir + L"\\dst2");
}
//---------------------------------------------------------------------------
結果
- CopyFolder()の処理時間: 1934msec程度
- CopyFiled()の処理時間: 1232msec程度
キャッシュ(?)などが効くためか、処理時間は800msecになったり上記の時間になったりする。だいたいの処理時間としては2000msec程度。
関連
c++ builder / fileIO > TFile::Copy() > 259ファイル 11.903秒 > プログレスバーが必要
こちらのリンク記事ではTThread内で処理をしていたためか、88MBファイルコピーで11.9秒かかっていた。
TForm上で処理するのとTThreadで処理するのは一長一短がある。
TFormだと処理は速い分、優先度の制御ができなかったはず。
TThreadだと優先度の制御ができる分、優先度を下げると割込みが入って処理時間がかかるという認識。