# http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!756.entry
cls
cd "C:\archived\self\task\powershell\test"
$file ="C:\archived\self\task\powershell\test\12.3MB.txt"
$file
function ReadCount
{
$ht = @{};
for ($i = 1; $i -le 10MB; $i *= 10)
{
#write-progress "Measuring gc -readCount $i" "% Complete" -perc ([math]::log10($i)*100/[math]::log10(10MB))
$ts = measure-command { gc $file -read $i | %{$_} }
$ht[$i] = $ts
}
$ht.Keys | sort |select @{n='ReadCount';e={$_}}, @{n='ElapsedTime';e={$ht[$_].ToString()}} | ft -a
}
function f1
{
Get-Content $file
}
function f2
{
switch -regex -file ($file) {default {}}
}
function f3
{
Invoke-Expression "`${$file}"
}
function f4
{
[System.IO.File]::ReadAllLines($file)
}
function MeasereGetContent
{
# measure
(measure-command {f1}).ToString()#.TotalMilliseconds
(measure-command {f2}).ToString()#.TotalMilliseconds
(measure-command {f3}).ToString()#.TotalMilliseconds
(measure-command {f4}).ToString()#.TotalMilliseconds
}
function CombineFile
{
gc $file -ReadCount 10000 |Add-Content addContentTesting.txt -Encoding Ascii
}
function GetCountOfFile
{
gc $file -ReadCount 10000 |%{$count=0} {$count+=$_.count} {$count}
}
function directory-summary($dir=".") {
get-childitem $dir |
% { $f = $_ ;
get-childitem -r $_.FullName |
measure-object -property length -sum |
select @{Name="Name";Expression={$f}},Sum}
}
#ReadCount
#MeasereGetContent
#CombineFile
#(measure-command { gc $file -read 2 | %{$_} }).ToString()
#(measure-command { gc $file | %{$_} }).ToString()
#(measure-command{GetLastLines}).ToString()
#GetCountOfFile
#(measure-command{GetCountOfFile}).ToString()
#$A=select-string "C:\archived\self\task\powershell\test\984MB.txt" -pattern "007924AF0"
#(measure-command{$A=select-string "C:\archived\self\task\powershell\test\984MB.txt" -pattern "007924AF0"}).ToString()