DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

dsnote不同实现方案性能对比


测试标准:在1699个文本文件中搜索 logon,查看总用时。

PowerShell 和 Bash 版本 dsnote 性能对比

测试环境:cygwin in Windows 10

测试过程:

$ time powershell -f apps/dsnote/donshell.ps1 s logon
powershell -f apps/dsnote/donshell.ps1 s logon  0.00s user 0.01s system 2% cpu 0.571 total
$ time ~/apps/dsnote/donshell.sh s logon
/home/lee_c/apps/dsnote/donshell.sh s logon  0.36s user 0.55s system 100% cpu 0.933 total

测试结果: 多次测试 Powershell 版稳定在 0.5 ~ 0.6 秒,bash 版稳定在 0.9 ~ 1 秒。

Winodws版本搜索方案对比

测试环境:Powershell in Windows 10

基于Powershell的搜索实现:

$res = "$repo\*$noteFileExt"
foreach ($kw in $items) {
  $res = Select-String -Path $res -Pattern $kw | % { $_.Path } | Get-Unique
  if ($res.Length -eq 0) {
    Write-Host Nothing match.
    return
  }
}

基于pt的搜索实现:

$res = $repo
foreach ($kw in $items) {
  $res = @(pt /i /l $kw $res)
  if ($res.length -eq 0) {
    Write-Host Nothing match.
    return
  }
}

测试过程:

PS> Measure-Command { C:\apps\cygRoot\home\lee_c\apps\dsnote\donshell.ps1 s logon }

测试结果: 多次测试 Powershell 版稳定在 200ms ~ 230ms 间,pt 版稳定在 210ms ~ 240ms 间, 另外 Powershell 版本中 Select-String 如果加 -SimpleMatch 参数, 运行时间反而增加到了 300ms 左右。

Powershell版本没有外部依赖,性能也不错,决定用它代替之前的pt版本。



Published

Aug 6, 2017

Last Updated

Aug 6, 2017

Category

Tech

Tags

  • bash 5
  • dsnote 1
  • powershell 2
  • time 7
  • timeit 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor