mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 15:17:47 +00:00
several attempts at making it faster
This commit is contained in:
parent
6b199476c8
commit
39834276b3
1 changed files with 60 additions and 1 deletions
|
@ -11,6 +11,8 @@ function Get-Character {
|
||||||
return $index -ge ($mystring.Length) ? ' ' : $mystring[$index]
|
return $index -ge ($mystring.Length) ? ' ' : $mystring[$index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# write one cell at at time moving the cursor across the screen
|
||||||
|
# ~1900 ms
|
||||||
function main {
|
function main {
|
||||||
# This is the same script as gradient.ps1 but hard coded
|
# This is the same script as gradient.ps1 but hard coded
|
||||||
# to 40x160 for nushell comparisions
|
# to 40x160 for nushell comparisions
|
||||||
|
@ -24,4 +26,61 @@ function main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
# Store the row in an array and then iterate the array to print it out a row at a time
|
||||||
|
# ~180 ms - This is printing double bytes or something - not sure what's going on
|
||||||
|
# Note that the x loop has half the characters so it doesn't count
|
||||||
|
function main2 {
|
||||||
|
# This is the same script as gradient.ps1 but hard coded
|
||||||
|
# to 40x160 for nushell comparisions
|
||||||
|
for ($y = 0; $y -le 39; $y++) {
|
||||||
|
$Color = 25
|
||||||
|
$row = @()
|
||||||
|
for ($x = 0; $x -le 79; $x++) {
|
||||||
|
$row += ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $x))
|
||||||
|
$Color += 2
|
||||||
|
}
|
||||||
|
$row += "`e[0m`n"
|
||||||
|
,$row | foreach{Write-Host $_ -NoNewline}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Store the characters in a string and contatenate, then output a row at a time
|
||||||
|
# ~265 ms
|
||||||
|
function main3 {
|
||||||
|
# This is the same script as gradient.ps1 but hard coded
|
||||||
|
# to 40x160 for nushell comparisions
|
||||||
|
for ($y = 0; $y -le 39; $y++) {
|
||||||
|
$Color = 25
|
||||||
|
$row = ""
|
||||||
|
for ($x = 0; $x -le 159; $x++) {
|
||||||
|
$row += ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $x))
|
||||||
|
$Color += 2
|
||||||
|
}
|
||||||
|
$row += "`e[0m"
|
||||||
|
Write-Host $row
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Store as a stringbuilder object
|
||||||
|
# ~240 ms
|
||||||
|
function main4 {
|
||||||
|
# This is the same script as gradient.ps1 but hard coded
|
||||||
|
# to 40x160 for nushell comparisions
|
||||||
|
$row = [System.Text.StringBuilder]""
|
||||||
|
for ($y = 0; $y -le 39; $y++) {
|
||||||
|
$Color = 25
|
||||||
|
$row.Clear()
|
||||||
|
for ($x = 0; $x -le 159; $x++) {
|
||||||
|
$row.Append("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $x))
|
||||||
|
$Color += 2
|
||||||
|
}
|
||||||
|
$row.Append("`e[0m")
|
||||||
|
Write-Host $row.ToString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# measure-command -expression { .\gradient_40x160.ps1 }
|
||||||
|
# main
|
||||||
|
# main2
|
||||||
|
# main3
|
||||||
|
main4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue