Update the measure-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2023-08-21 21:23:10 +02:00
parent 14b028e1ce
commit 345da64609
9 changed files with 40 additions and 39 deletions

View File

@ -1,21 +1,21 @@
<#
.SYNOPSIS
Measures the BubbleSort algorithm
Measures the speed of BubbleSort
.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,
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
comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.
.PARAMETER numIntegers
Specifies the number of integers to sort
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-bubblesort.ps1
🕒 BubbleSort of 1000 integers took 0.7291663 sec
PS> ./measure-BubbleSort.ps1
🧭 Sorting 1000 integers by BubbleSort took 0.7291663 sec
.LINK
https://github.com/fleschutz/PowerShell
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
Author: Markus Fleschutz | License: CC0
#>
param([int]$numIntegers = 1000)
@ -40,5 +40,5 @@ $list = (1..$NumIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[BubbleSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 BubbleSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by BubbleSort took $elapsed sec"
exit 0 # success

View File

@ -1,9 +1,9 @@
<#
.SYNOPSIS
Measures the BucketSort algorithm
Measures the speed of BucketSort
.DESCRIPTION
This PowerShell script measures the speed of the BucketSort algorithm.
BubbleSort is a sorting algorithm that works by distributing the elements
This PowerShell script measures the speed of the BucketSort algorithm.
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,
either using a different sorting algorithm, or by recursively applying the bucket
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
to use, and whether the input is uniformly distributed.
.PARAMETER numIntegers
Specifies the number of integers to sort
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-bucketsort.ps1
🕒 BucketSort of 1000 integers took 0.0653755 sec
PS> ./measure-BucketSort.ps1
🧭 Sorting 1000 integers by BucketSort took 0.0653755 sec
.LINK
https://github.com/fleschutz/PowerShell
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
Author: Markus Fleschutz | License: CC0
#>
param([int]$numIntegers = 1000)
@ -63,5 +63,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[BucketSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 BucketSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by BucketSort took $elapsed sec"
exit 0 # success

View File

@ -1,6 +1,6 @@
<#
.SYNOPSIS
Measures the CountingSort algorithm
Measures the speed of CountingSort
.DESCRIPTION
This PowerShell script measures the speed of the CountingSort algorithm.
CountingSort is an algorithm for sorting a collection of objects according to keys
@ -16,7 +16,7 @@
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-CountingSort.ps1
🕒 CountingSort of 1000 integers took 0.0454597 sec
🧭 Sorting 1000 integers by CountingSort took 0.0454597 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -54,5 +54,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[CountingSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 CountingSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by CountingSort took $elapsed sec"
exit 0 # success

View File

@ -14,7 +14,7 @@
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-HeapSort.ps1
🕒 HeapSort of 1000 integers took 0.6145732 sec
🧭 Sorting 1000 integers by HeapSort took 0.6145732 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -71,5 +71,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[HeapSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 HeapSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by HeapSort took $elapsed sec"
exit 0 # success

View File

@ -10,7 +10,7 @@
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-InsertionSort.ps1
🕒 InsertionSort of 1000 integers took 0.4234268 sec
🧭 Sorting 1000 integers by InsertionSort took 0.4234268 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -44,5 +44,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[InsertionSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 InsertionSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by InsertionSort took $elapsed sec"
exit 0 # success

View File

@ -12,7 +12,7 @@
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-MergeSort.ps1
🕒 MergeSort of 1000 integers took 0.3786619 sec
🧭 Sorting 1000 integers by MergeSort took 0.3786619 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -67,5 +67,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[MergeSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 MergeSort of $numIntegers integers took $elapsed sec"
"🧭 Sorting $numIntegers integers by MergeSort took $elapsed sec"
exit 0 # success

View File

@ -11,7 +11,7 @@
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-QuickSort.ps1
🕒 QuickSort of 1000 integers took 0.0853411 sec
🧭 Sorting 1000 integers by QuickSort took 0.0853411 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -49,5 +49,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[QuickSort]::Sort($list, 0, $list.Count-1)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 QuickSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by QuickSort took $elapsed sec"
exit 0 # success

View File

@ -12,7 +12,7 @@
Specifies the number of integers to sort
.EXAMPLE
PS> ./measure-SelectionSort.ps1
🕒 SelectionSort of 1000 integers took 0.3351773 sec
🧭 Sorting 1000 integers by SelectionSort took 0.3351773 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -41,5 +41,5 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[SelectionSort]::Sort($list)
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
"🕒 SelectionSort of $numIntegers integers took $elapsed sec"
exit 0 # success
"🧭 Sorting $numIntegers integers by SelectionSort took $elapsed sec"
exit 0 # success

View File

@ -1,13 +1,13 @@
<#
.SYNOPSIS
Measure sorting algorithms
Measures the speed of sorting algorithms
.DESCRIPTION
This PowerShell script measures the speed of several sorting algorithms and prints it.
.PARAMETER numIntegers
Specifies the number of integers to sort (3000 by default)
.EXAMPLE
PS> ./measure-sorting-algorithms.ps1
🕒 BubbleSort of 3000 integers took 6.041561 sec
🧭 Sorting 3000 integers by BubbleSort took 6.041561 sec
...
.LINK
https://github.com/fleschutz/PowerShell
@ -16,6 +16,7 @@
#>
param([int]$numIntegers = 3000)
" "
& "$PSScriptRoot/measure-BubbleSort.ps1" $numIntegers
& "$PSScriptRoot/measure-BucketSort.ps1" $numIntegers