ちょっと遅すぎだわ・・・
Summary
外付けHDDにデーターを置いていろいろ作業してた
コピーする作業がものすごく遅い
パソコンで作業するなら内臓HDDの方がお得
Summary2
BashScriptは外付けHDDに関しての作業が苦手?
F#の方がBashScriptより早い気がする
Environment
~/tmp
(ins)$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14
BuildVersion: 18A391
~/tmp
(ins)$ uname -a
Darwin callmekoheis-MacBook-Air.local 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64
~/tmp
(ins)$ bash --version
GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
~/tmp
(ins)$ echo 'printfn "%A" <| System.Reflection.Assembly.GetAssembly( typeof<list<int>> ).FullName' | fsharpi --readline-
Microsoft (R) F# Interactive version 4.1
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> "FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
val it : unit = ()
いらいらポイント
外付けHDDから内臓HDDにコピーする作業
作業はこんな感じ
外付けHDDにあるデーター(主に写真データー)から必要な写真データーをフォルダ構成を変えて内臓HDDにコピーする(それだけ!)
外付けHDDにあるデータの様子
かかかる時間
F#の方が1分ほどbash script
より早いが、かなり遅いっ
bash script
4m22
F# script
3m39
内臓HDDでの作業
もしかして?とおもって、パソコンに内臓されているHDD
に外付けのHDD
にあるデーターをコピーしてみて、作業したら早くなった!
だいたい1分
書いてみたコード
ばばば、、、と書いたのであれかもしれない。。。
というか、そんなにコードとか書くの得意じゃないのであれかもしれない。。。
bash script
のコード
# SrcHDD_='/Volumes/kohei120GB'
SrcHDD_='/Users/callmekohei/Desktop/mytest'
DstHDD_='/Users/callmekohei/tmp4'
function createDstFilePath () {
echo $1 | sed \
-e 's/\.JPG/\.jpg/' \
-e 's/色補正後のデータ\///' \
-e 's#'$SrcHDD_'/DVD[1-9]/バラ写真#'$DstHDD_'/BA#' \
-e 's#'$SrcHDD_'/DVD[1-9]/フイルム#'$DstHDD_'/SL#' \
-e 's#'$SrcHDD_'/DVD[1-9]/ポケットフイルム#'$DstHDD_'/PF#'
}
function copyFiles () {
local srcFilePath
local dstFilePath
while read -r srcFilePath
do
dstFilePath=$( createDstFilePath $srcFilePath)
dstFolder=$( dirname $dstFilePath )
if [ ! -e $dstFolder ] ; then
mkdir -p $dstFolder
fi
cp -f $srcFilePath $dstFilePath
done
}
find $SrcHDD_/* -type f \
| grep '後' \
| copyFiles
F#
のコード
open System.IO
open System.Text.RegularExpressions
// let SrcHDD_ = "/Volumes/kohei120GB"
let SrcHDD_ = "/Users/callmekohei/Desktop/mytest"
let DstHDD_ = "/Users/callmekohei/tmp4"
// コピーしたい写真データーのリストを作成する
let srcJPGs () =
["DVD1";"DVD2";"DVD3";"DVD4"]
|> List.map ( fun s ->
Directory.GetFiles( SrcHDD_ + "/" + s ,"*", SearchOption.AllDirectories)
|> Array.filter ( fun (s:string) -> s.Contains("色補正後のデータ") )
)
// コピー元のファイルパスとコピー先のファイルパスを組み(タプル)にしたリストを作成する
let dstJPGs () =
srcJPGs ()
|> List.map( fun arr ->
arr
|> Array.map( fun srcPath ->
let destinateFilePath =
Regex.Replace( srcPath, @"色補正後のデータ/" , "" )
|> fun s -> Regex.Replace( s, SrcHDD_ + @"/DVD\d/バラ写真" , DstHDD_ + "/BA" )
|> fun s -> Regex.Replace( s, SrcHDD_ + @"/DVD\d/フイルム" , DstHDD_ + "/SL" )
|> fun s -> Regex.Replace( s, SrcHDD_ + @"/DVD\d/ポケットフイルム" , DstHDD_ + "/PF" )
|> fun s -> Regex.Replace( s, ".JPG", ".jpg" )
srcPath, destinateFilePath
)
)
// もしコピー先のフォルダがなければ作成する
let createFolderIfnotExists () =
dstJPGs ()
|> List.map ( fun arr ->
arr
|> Array.map( fun tpl -> System.IO.Path.GetDirectoryName( tpl |> snd ) )
|> Array.distinct )
|> List.iter( fun arr ->
arr
|> Array.iter( fun folderPath ->
if not ( Directory.Exists( folderPath ) ) then
Directory.CreateDirectory( folderPath ) |> ignore
)
)
let main () =
createFolderIfnotExists ()
dstJPGs ()
|> List.map ( fun arr ->
arr |> Array.iter ( fun (src,dst) -> File.Copy(src, dst) ) )
main ()
追記 2018.11.5 mon 00:34
copy
メソッドをパラレルしてみました!
外付けHDDから内臓HDDにコピーする際パラレルすると大幅に遅くなります!それ以外(同一HD)だと早くなります!ふむ〜。なぜに??
parallel | src hdd | dst hdd | time |
---|---|---|---|
x | outer | inner | 3m39.562s |
o | outer | inner | 8m41.194s |
x | inner | inner | 1m04.923s |
o | inner | inner | 44.122s |
x | outer | outer | 9m27.624s |
o | outer | outer | 8m29.336s |
コード
let main () =
createFolderIfnotExists ()
dstJPGs ()
|> Array.concat
|> Array.map ( fun (src,dst) -> async{ File.Copy(src, dst) } )
|> Async.Parallel
|> Async.RunSynchronously