Skip to content

Instantly share code, notes, and snippets.

@RaphSku
Created August 16, 2023 10:27
Show Gist options
  • Save RaphSku/8cb9aae84ea374de85d621b6cc6bf8f5 to your computer and use it in GitHub Desktop.
Save RaphSku/8cb9aae84ea374de85d621b6cc6bf8f5 to your computer and use it in GitHub Desktop.
Test Output for shell package & Benchmark Test for Code Enhancement of GitTopLevelDir
Test Command:
go test -benchmem -run=^$ -bench ^BenchmarkPerformanceOfGitTopLevelDir$ ./shell/ -count=20
Old Code:
goos: linux
goarch: amd64
pkg: github.com/gruntwork-io/terragrunt/shell
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkPerformanceOfGitTopLevelDir-12 1024 1164571 ns/op 78920 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1015 1157780 ns/op 78871 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1036 1147853 ns/op 78881 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1003 1140353 ns/op 78877 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 968 1160739 ns/op 78873 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1015 1158605 ns/op 78868 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1060 1131602 ns/op 78865 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1041 1162521 ns/op 78880 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 960 1147543 ns/op 78891 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 985 1142251 ns/op 78870 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1034 1141295 ns/op 78867 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1038 1171650 ns/op 78868 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1023 1165989 ns/op 78867 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1054 1148353 ns/op 78868 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1005 1154453 ns/op 78871 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1048 1166332 ns/op 78868 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1028 1163298 ns/op 78872 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1009 1153608 ns/op 78872 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1008 1151338 ns/op 78870 B/op 154 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 1052 1161161 ns/op 78866 B/op 154 allocs/op
PASS
ok github.com/gruntwork-io/terragrunt/shell 26.003s
New Code:
goos: linux
goarch: amd64
pkg: github.com/gruntwork-io/terragrunt/shell
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkPerformanceOfGitTopLevelDir-12 225628 5097 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 228072 5094 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 236029 5169 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 218100 5145 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 214365 5229 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 206799 5150 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 230037 5193 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 213496 5214 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 233116 5209 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 231043 5116 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 227992 5140 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 233667 5193 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 214869 5189 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 233390 5113 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 233338 5093 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 228385 5190 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 228594 5156 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 224140 5124 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 235503 5117 ns/op 4159 B/op 28 allocs/op
BenchmarkPerformanceOfGitTopLevelDir-12 234692 5325 ns/op 4159 B/op 28 allocs/op
PASS
ok github.com/gruntwork-io/terragrunt/shell 24.531s
Benchstat:
goos: linux
goarch: amd64
pkg: github.com/gruntwork-io/terragrunt/shell
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
PerformanceOfGitTopLevelDir-12 1156.117µ ± 1% 5.153µ ± 1% -99.55% (p=0.000 n=20)
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
PerformanceOfGitTopLevelDir-12 77.022Ki ± 0% 4.062Ki ± 0% -94.73% (p=0.000 n=20)
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
PerformanceOfGitTopLevelDir-12 154.00 ± 0% 28.00 ± 0% -81.82% (p=0.000 n=20)
Test Output of `go test -v ./shell`:
=== RUN TestExplainError
=== PAUSE TestExplainError
=== RUN TestCommandOutputOrder
=== PAUSE TestCommandOutputOrder
=== RUN TestCommandOutputPrefix
time=2023-08-16T12:05:20+02:00 level=debug msg=Running command: ../testdata/test_outputs.sh same
--- PASS: TestCommandOutputPrefix (4.12s)
=== RUN TestRunShellCommand
=== PAUSE TestRunShellCommand
=== RUN TestRunShellOutputToStderrAndStdout
=== PAUSE TestRunShellOutputToStderrAndStdout
=== RUN TestExitCodeUnix
=== PAUSE TestExitCodeUnix
=== RUN TestNewSignalsForwarderWaitUnix
=== PAUSE TestNewSignalsForwarderWaitUnix
=== RUN TestNewSignalsForwarderMultipleUnix
=== PAUSE TestNewSignalsForwarderMultipleUnix
=== RUN TestRunShellCommandWithOutputInterrupt
=== PAUSE TestRunShellCommandWithOutputInterrupt
=== CONT TestExplainError
=== RUN TestExplainError/Error_refreshing_state:_AccessDenied:_Access_Denied
=== CONT TestExitCodeUnix
=== RUN TestExplainError/Error:_Initialization_required
=== RUN TestExplainError/Module_source_has_changed
--- PASS: TestExplainError (0.00s)
--- PASS: TestExplainError/Error_refreshing_state:_AccessDenied:_Access_Denied (0.00s)
--- PASS: TestExplainError/Error:_Initialization_required (0.00s)
--- PASS: TestExplainError/Module_source_has_changed (0.00s)
=== CONT TestRunShellOutputToStderrAndStdout
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: terraform --version
=== CONT TestRunShellCommand
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: terraform --version
=== CONT TestCommandOutputOrder
=== RUN TestCommandOutputOrder/withPtty
=== PAUSE TestCommandOutputOrder/withPtty
=== RUN TestCommandOutputOrder/withoutPtty
=== PAUSE TestCommandOutputOrder/withoutPtty
=== CONT TestCommandOutputOrder/withPtty
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: ../testdata/test_outputs.sh same
=== CONT TestCommandOutputOrder/withoutPtty
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: ../testdata/test_outputs.sh same
=== CONT TestRunShellCommandWithOutputInterrupt
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: ../testdata/test_sigint_wait.sh 5
=== CONT TestNewSignalsForwarderWaitUnix
=== CONT TestNewSignalsForwarderMultipleUnix
Terraform v1.5.5
on linux_amd64
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: terraform not-a-real-command
time=2023-08-16T12:05:24+02:00 level=debug msg=Running command: terraform --version
Terraform has no command named "not-a-real-command".
To see all of Terraform's top-level commands, run:
terraform -help
--- PASS: TestRunShellCommand (0.22s)
--- PASS: TestRunShellOutputToStderrAndStdout (0.25s)
--- PASS: TestExitCodeUnix (1.40s)
time=2023-08-16T12:05:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-16T12:05:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-16T12:05:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-16T12:05:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-16T12:05:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
--- PASS: TestCommandOutputOrder (0.00s)
--- PASS: TestCommandOutputOrder/withPtty (4.10s)
--- PASS: TestCommandOutputOrder/withoutPtty (4.13s)
--- PASS: TestNewSignalsForwarderWaitUnix (6.08s)
--- PASS: TestNewSignalsForwarderMultipleUnix (6.52s)
time=2023-08-16T12:05:57+02:00 level=debug msg=Forward signal interrupt to terraform.
--- PASS: TestRunShellCommandWithOutputInterrupt (38.05s)
PASS
ok github.com/gruntwork-io/terragrunt/shell (cached)
@RaphSku
Copy link
Author

RaphSku commented Aug 25, 2023

New Benchmark with GenericCache:
goos: linux
goarch: amd64
pkg: github.com/gruntwork-io/terragrunt/shell
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
│ old.txt │ new2.txt │
│ sec/op │ sec/op vs base │
PerformanceOfGitTopLevelDir-12 1156.117µ ± 1% 5.932µ ± 1% -99.49% (p=0.000 n=20)
│ old.txt │ new2.txt │
│ B/op │ B/op vs base │
PerformanceOfGitTopLevelDir-12 77.022Ki ± 0% 4.190Ki ± 0% -94.56% (p=0.000 n=20)
│ old.txt │ new2.txt │
│ allocs/op │ allocs/op vs base │
PerformanceOfGitTopLevelDir-12 154.00 ± 0% 31.00 ± 0% -79.87% (p=0.000 n=20)

TestOutputs with new GenericCache:
=== RUN TestStringCacheCreation
=== PAUSE TestStringCacheCreation
=== RUN TestStringCacheOperation
=== PAUSE TestStringCacheOperation
=== RUN TestIAMRoleOptionsCacheOperation
=== PAUSE TestIAMRoleOptionsCacheOperation
=== CONT TestStringCacheCreation
--- PASS: TestStringCacheCreation (0.00s)
=== CONT TestStringCacheOperation
=== CONT TestIAMRoleOptionsCacheOperation
--- PASS: TestStringCacheOperation (0.00s)
--- PASS: TestIAMRoleOptionsCacheOperation (0.00s)
PASS
ok github.com/gruntwork-io/terragrunt/cache 0.006s

=== RUN TestExplainError
=== PAUSE TestExplainError
=== RUN TestCommandOutputOrder
=== PAUSE TestCommandOutputOrder
=== RUN TestCommandOutputPrefix
time=2023-08-25T09:26:20+02:00 level=debug msg=Running command: ../testdata/test_outputs.sh same
--- PASS: TestCommandOutputPrefix (4.01s)
=== RUN TestRunShellCommand
=== PAUSE TestRunShellCommand
=== RUN TestRunShellOutputToStderrAndStdout
=== PAUSE TestRunShellOutputToStderrAndStdout
=== RUN TestGitLevelTopDirCaching
=== PAUSE TestGitLevelTopDirCaching
=== RUN TestExitCodeUnix
=== PAUSE TestExitCodeUnix
=== RUN TestNewSignalsForwarderWaitUnix
=== PAUSE TestNewSignalsForwarderWaitUnix
=== RUN TestNewSignalsForwarderMultipleUnix
=== PAUSE TestNewSignalsForwarderMultipleUnix
=== RUN TestRunShellCommandWithOutputInterrupt
=== PAUSE TestRunShellCommandWithOutputInterrupt
=== CONT TestExplainError
=== RUN TestExplainError/Error_refreshing_state:_AccessDenied:_Access_Denied
=== CONT TestExitCodeUnix
=== RUN TestExplainError/Error:_Initialization_required
=== CONT TestRunShellOutputToStderrAndStdout
=== RUN TestExplainError/Module_source_has_changed
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: terraform --version
=== CONT TestNewSignalsForwarderWaitUnix
--- PASS: TestExplainError (0.00s)
--- PASS: TestExplainError/Error_refreshing_state:_AccessDenied:_Access_Denied (0.00s)
--- PASS: TestExplainError/Error:_Initialization_required (0.00s)
--- PASS: TestExplainError/Module_source_has_changed (0.00s)
=== CONT TestGitLevelTopDirCaching
=== CONT TestRunShellCommand
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: git rev-parse --show-toplevel
time=2023-08-25T09:26:24+02:00 level=debug msg=Command output will be suppressed.
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: terraform --version
=== CONT TestRunShellCommandWithOutputInterrupt
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: ../testdata/test_sigint_wait.sh 5
=== CONT TestNewSignalsForwarderMultipleUnix
=== CONT TestCommandOutputOrder
=== RUN TestCommandOutputOrder/withPtty
=== PAUSE TestCommandOutputOrder/withPtty
=== RUN TestCommandOutputOrder/withoutPtty
=== PAUSE TestCommandOutputOrder/withoutPtty
=== CONT TestCommandOutputOrder/withPtty
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: ../testdata/test_outputs.sh same
=== CONT TestCommandOutputOrder/withoutPtty
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: ../testdata/test_outputs.sh same
time=2023-08-25T09:26:24+02:00 level=debug msg=git show-toplevel result:

--- PASS: TestGitLevelTopDirCaching (0.02s)
Terraform v1.5.5
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.5.6. You can update by downloading from https://www.terraform.io/downloads.html
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: terraform not-a-real-command
time=2023-08-25T09:26:24+02:00 level=debug msg=Running command: terraform --version
Terraform has no command named "not-a-real-command".

To see all of Terraform's top-level commands, run:
terraform -help

--- PASS: TestRunShellCommand (0.09s)
--- PASS: TestRunShellOutputToStderrAndStdout (0.10s)
--- PASS: TestExitCodeUnix (0.52s)
time=2023-08-25T09:26:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-25T09:26:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-25T09:26:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-25T09:26:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
time=2023-08-25T09:26:27+02:00 level=debug msg=Interrupt signal received. Gracefully shutting down... (it can take up to 30s)
--- PASS: TestCommandOutputOrder (0.00s)
--- PASS: TestCommandOutputOrder/withoutPtty (4.01s)
--- PASS: TestCommandOutputOrder/withPtty (4.01s)
--- PASS: TestNewSignalsForwarderWaitUnix (6.05s)
--- PASS: TestNewSignalsForwarderMultipleUnix (6.51s)
time=2023-08-25T09:26:57+02:00 level=debug msg=Forward signal interrupt to terraform.
--- PASS: TestRunShellCommandWithOutputInterrupt (38.12s)
PASS
ok github.com/gruntwork-io/terragrunt/shell 42.134s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment