mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-26 14:26:10 +01:00
Update the measure-*.ps1 scripts
This commit is contained in:
parent
14b028e1ce
commit
345da64609
@ -1,21 +1,21 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Measures the BubbleSort algorithm
|
Measures the speed of BubbleSort
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script measures the speed of the BubbleSort algorithm.
|
This PowerShell script measures the speed of the BubbleSort algorithm.
|
||||||
BubbleSort is a simple sorting algorithm that repeatedly steps through the list,
|
BubbleSort is a simple sorting algorithm that repeatedly steps through the list,
|
||||||
compares adjacent elements and swaps them if they are in the wrong order. The pass
|
compares adjacent elements and swaps them if they are in the wrong order. The pass
|
||||||
through the list is repeated until the list is sorted. The algorithm, which is a
|
through the list is repeated until the list is sorted. The algorithm, which is a
|
||||||
comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.
|
comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.
|
||||||
.PARAMETER numIntegers
|
.PARAMETER numIntegers
|
||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-bubblesort.ps1
|
PS> ./measure-BubbleSort.ps1
|
||||||
🕒 BubbleSort of 1000 integers took 0.7291663 sec
|
🧭 Sorting 1000 integers by BubbleSort took 0.7291663 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([int]$numIntegers = 1000)
|
param([int]$numIntegers = 1000)
|
||||||
@ -40,5 +40,5 @@ $list = (1..$NumIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[BubbleSort]::Sort($list)
|
[BubbleSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 BubbleSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by BubbleSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Measures the BucketSort algorithm
|
Measures the speed of BucketSort
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script measures the speed of the BucketSort algorithm.
|
This PowerShell script measures the speed of the BucketSort algorithm.
|
||||||
BubbleSort is a sorting algorithm that works by distributing the elements
|
BucketSort is a sorting algorithm that works by distributing the elements
|
||||||
of an array into a number of buckets. Each bucket is then sorted individually,
|
of an array into a number of buckets. Each bucket is then sorted individually,
|
||||||
either using a different sorting algorithm, or by recursively applying the bucket
|
either using a different sorting algorithm, or by recursively applying the bucket
|
||||||
sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort
|
sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort
|
||||||
@ -13,14 +13,14 @@
|
|||||||
complexity depends on the algorithm used to sort each bucket, the number of buckets
|
complexity depends on the algorithm used to sort each bucket, the number of buckets
|
||||||
to use, and whether the input is uniformly distributed.
|
to use, and whether the input is uniformly distributed.
|
||||||
.PARAMETER numIntegers
|
.PARAMETER numIntegers
|
||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-bucketsort.ps1
|
PS> ./measure-BucketSort.ps1
|
||||||
🕒 BucketSort of 1000 integers took 0.0653755 sec
|
🧭 Sorting 1000 integers by BucketSort took 0.0653755 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([int]$numIntegers = 1000)
|
param([int]$numIntegers = 1000)
|
||||||
@ -63,5 +63,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[BucketSort]::Sort($list)
|
[BucketSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 BucketSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by BucketSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Measures the CountingSort algorithm
|
Measures the speed of CountingSort
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script measures the speed of the CountingSort algorithm.
|
This PowerShell script measures the speed of the CountingSort algorithm.
|
||||||
CountingSort is an algorithm for sorting a collection of objects according to keys
|
CountingSort is an algorithm for sorting a collection of objects according to keys
|
||||||
@ -16,7 +16,7 @@
|
|||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-CountingSort.ps1
|
PS> ./measure-CountingSort.ps1
|
||||||
🕒 CountingSort of 1000 integers took 0.0454597 sec
|
🧭 Sorting 1000 integers by CountingSort took 0.0454597 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -54,5 +54,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[CountingSort]::Sort($list)
|
[CountingSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 CountingSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by CountingSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-HeapSort.ps1
|
PS> ./measure-HeapSort.ps1
|
||||||
🕒 HeapSort of 1000 integers took 0.6145732 sec
|
🧭 Sorting 1000 integers by HeapSort took 0.6145732 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -71,5 +71,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[HeapSort]::Sort($list)
|
[HeapSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 HeapSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by HeapSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-InsertionSort.ps1
|
PS> ./measure-InsertionSort.ps1
|
||||||
🕒 InsertionSort of 1000 integers took 0.4234268 sec
|
🧭 Sorting 1000 integers by InsertionSort took 0.4234268 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -44,5 +44,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[InsertionSort]::Sort($list)
|
[InsertionSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 InsertionSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by InsertionSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-MergeSort.ps1
|
PS> ./measure-MergeSort.ps1
|
||||||
🕒 MergeSort of 1000 integers took 0.3786619 sec
|
🧭 Sorting 1000 integers by MergeSort took 0.3786619 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -67,5 +67,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[MergeSort]::Sort($list)
|
[MergeSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 MergeSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by MergeSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-QuickSort.ps1
|
PS> ./measure-QuickSort.ps1
|
||||||
🕒 QuickSort of 1000 integers took 0.0853411 sec
|
🧭 Sorting 1000 integers by QuickSort took 0.0853411 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -49,5 +49,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[QuickSort]::Sort($list, 0, $list.Count-1)
|
[QuickSort]::Sort($list, 0, $list.Count-1)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 QuickSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by QuickSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
Specifies the number of integers to sort
|
Specifies the number of integers to sort
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-SelectionSort.ps1
|
PS> ./measure-SelectionSort.ps1
|
||||||
🕒 SelectionSort of 1000 integers took 0.3351773 sec
|
🧭 Sorting 1000 integers by SelectionSort took 0.3351773 sec
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -41,5 +41,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
[SelectionSort]::Sort($list)
|
[SelectionSort]::Sort($list)
|
||||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"🕒 SelectionSort of $numIntegers integers took $elapsed sec"
|
"🧭 Sorting $numIntegers integers by SelectionSort took $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Measure sorting algorithms
|
Measures the speed of sorting algorithms
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script measures the speed of several sorting algorithms and prints it.
|
This PowerShell script measures the speed of several sorting algorithms and prints it.
|
||||||
.PARAMETER numIntegers
|
.PARAMETER numIntegers
|
||||||
Specifies the number of integers to sort (3000 by default)
|
Specifies the number of integers to sort (3000 by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./measure-sorting-algorithms.ps1
|
PS> ./measure-sorting-algorithms.ps1
|
||||||
🕒 BubbleSort of 3000 integers took 6.041561 sec
|
🧭 Sorting 3000 integers by BubbleSort took 6.041561 sec
|
||||||
...
|
...
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
param([int]$numIntegers = 3000)
|
param([int]$numIntegers = 3000)
|
||||||
|
|
||||||
" "
|
" "
|
||||||
& "$PSScriptRoot/measure-BubbleSort.ps1" $numIntegers
|
& "$PSScriptRoot/measure-BubbleSort.ps1" $numIntegers
|
||||||
& "$PSScriptRoot/measure-BucketSort.ps1" $numIntegers
|
& "$PSScriptRoot/measure-BucketSort.ps1" $numIntegers
|
||||||
|
Loading…
Reference in New Issue
Block a user