PoshCode Archive  Artifact [66e012ae23]

Artifact 66e012ae23c8ee25f793ff88f7239ea8da49731f10fa9dcf6a08a4f9661cecbf:

  • File Hash-efficiency-example.ps1 — part of check-in [1f07f098aa] at 2018-06-10 14:12:11 on branch trunk — TLDR: $hash.$name = $value is stupidly inefficient. (user: BattleChicken size: 678)

# encoding: ascii
# api: powershell
# title: Hash efficiency example
# description: TLDR:  $hash.$name = $value is stupidly inefficient.
# version: 0.1
# author: BattleChicken
# license: CC0
# x-poshcode-id: 6283
# x-archived: 2016-11-18T17:09:26
# x-published: 2016-04-06T23:04:00
#
#
$rng = 10000
(Measure-Command {
    $hash = @{}
    foreach ($a in 1..$rng){
        $hash[$a] = $a
    }
}).totalmilliseconds

(Measure-Command {
    $hash = @{}
    foreach ($a in 1..$rng){
        $hash.$a = $a
    }
}).TotalMilliseconds

(Measure-Command {
    $hash = @{}
    foreach ($a in 1..$rng){
        $hash.add($a, $a)
    }
}).TotalMilliseconds