Created
December 15, 2017 21:35
-
-
Save HumanEquivalentUnit/183bfd109bb28cce644b3f60ca83d81f to your computer and use it in GitHub Desktop.
adventofcode powershell vs c# timings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# C# runs in ~0.5 seconds. | |
# powershell commented out below runs in ~23 seconds. | |
# correct answer is 567 | |
Add-Type @' | |
using System; | |
public class MyType1 | |
{ | |
public long crunch() { | |
long gA = 512; | |
long gB = 191; | |
long bitmask = 65535; | |
long numMatches = 0; | |
for (long i=0; i < 40000000; i++) | |
{ | |
gA = (gA * 16807) % 2147483647; | |
gB = (gB * 48271) % 2147483647; | |
if ( (gA & bitmask) == (gB & bitmask) ) { numMatches++; } | |
} | |
return numMatches; | |
} | |
} | |
'@ -Language CSharp | |
$obj1 = New-Object MyType1 | |
$obj1.crunch() | |
#[uint64]$gA = 512 | |
#[uint64]$gB = 191 | |
# | |
#[uint16]$bitmask = 65535 | |
#[uint64]$numMatches = 0 | |
#for ([uint64]$i=0; $i -lt 40000000; $i++) | |
#{ | |
# | |
# $gA = ($gA * 16807) % 2147483647 | |
# $gB = ($gB * 48271) % 2147483647 | |
# | |
# if ( ($gA -band $bitmask) -eq ($gB -band $bitmask) ) { $numMatches++ } | |
#} | |
# | |
#$numMatches | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment