clipboard icon indicating copy to clipboard operation
clipboard copied to clipboard

Windows 7 / Powershell 2 compatibility

Open divinity76 opened this issue 3 years ago • 2 comments

Get-Clipboard was introduced in PowerShell 3, which means it won't work on your average Windows 7 system. the old code is PS3+ compatible, and the new code is PS2+ compatible.

Edit: this should also make it Vista/XP/Server 2003/Server 2008 compatible, but the oldest i've actually tested is 7.

divinity76 avatar Jul 01 '21 15:07 divinity76

Hyperfine benchmarks:

$ cat approach1.bat
powershell.exe -Command Get-Clipboard
$ cat approach2.bat
powershell -sta "add-type -as System.Windows.Forms; [windows.forms.clipboard]::GetText()"
$ hyperfine "approach1.bat"
Benchmark #1: approach1.bat                                                                                                       0
  Time (mean ± σ):     352.0 ms ±  11.7 ms    [User: 1.4 ms, System: 5.0 ms]                                                      0
  Range (min … max):   341.1 ms … 382.5 ms    10 runs
$ hyperfine "approach2.bat"
Benchmark #1: approach2.bat                                                                                                       0
  Time (mean ± σ):     374.5 ms ±   6.3 ms    [User: 1.4 ms, System: 6.5 ms]                                                      0
  Range (min … max):   365.7 ms … 389.4 ms    10 runs
$ hyperfine "approach1.bat"
Benchmark #1: approach1.bat                                                                                                       0
  Time (mean ± σ):     386.8 ms ±  25.9 ms    [User: 0.0 ms, System: 4.1 ms]                                                      0
  Range (min … max):   358.7 ms … 444.3 ms    10 runs
$ hyperfine "approach2.bat"
Benchmark #1: approach2.bat                                                                                                       0
  Time (mean ± σ):     417.9 ms ±  21.5 ms    [User: 4.2 ms, System: 5.0 ms]                                                      0
  Range (min … max):   386.7 ms … 461.6 ms    10 runs

~ TL;DR the new code is about 20 milliseconds slower on my i7-8565U CPU @ 1.8GHz with 2133Mh/s ram (unfortunately a lot of background noise during benchmarking, don't have any easy way to fix that, the absolute best runs should be the most accurate representation of performance impact though)

divinity76 avatar Jul 01 '21 16:07 divinity76

This repository is no longer maintained, feel free to maintain your own fork

rehhouari avatar Oct 01 '21 14:10 rehhouari