Go Demo Benchmark

A demo benchmark to preview all the functions of go-benchmarks and to validate them.

Description:

This demo benchmark is customized to display all the functions of go-benchmarks. The results can be used to validate if the charts match the raw benchmark data. It can also be used to see what go-benchmarks can do.

Implementations

Green marks the fastest implementation, red marks the slowest

Comparison

This section compares the performance of Demo implementations with the functions: run

Different Run Count

Different CPU Core Count

Faster Over Time

This benchmark gets faster, the more runs it has.

Function ns/op ops/sec B/op allocs/op MB/s
run 43437.57 207979 0.0 0 0.0

Comparison

  • Faster Over Time run is 1004.17% slower than Faster With More CPU Cores run.
  • Faster Over Time run is 129.99% slower than Slower Over Time run.
func BenchmarkFasterOverTime_run(b *testing.B) {
	const maxDelay = 1000 // Maximum delay in nanoseconds
	for i := 0; i < b.N; i++ {
		// Calculate the sleep duration, ensuring it's never less than 0
		delay := maxDelay - i
		if delay < 0 {
			delay = 0
		}
		time.Sleep(time.Duration(delay) * time.Nanosecond)
	}
}

Faster Over Time run

ns/op ops/sec B/op allocs/op MB/s
43437.57 207979 0.0 0 0.0
By Run Count
By CPU Core Count

Faster With More CPU Cores

This benchmark gets faster, the more CPU cores it has.

Function ns/op ops/sec B/op allocs/op MB/s
run 3933.95 332274 258.3 2 0.0

Comparison

  • Faster With More CPU Cores run is 90.94% faster than Faster Over Time run.
  • Faster With More CPU Cores run is 79.17% faster than Slower Over Time run.
func BenchmarkFasterWithMoreCPUCores_run(b *testing.B) {
	done := make(chan bool)

	for i := 0; i < b.N; i++ {
		go func() {
			// Increase the workload inside the goroutine
			time.Sleep(10000000 * time.Nanosecond)

			done <- true
		}()
	}

	// Wait for all goroutines to finish
	for i := 0; i < b.N; i++ {
		<-done
	}
}

Faster With More CPU Cores run

ns/op ops/sec B/op allocs/op MB/s
3933.95 332274 258.3 2 0.0
By Run Count
By CPU Core Count

Slower Over Time

This benchmark gets slower, the more runs it has.

Function ns/op ops/sec B/op allocs/op MB/s
run 18886.59 1219321 0.0 0 0.0

Comparison

  • Slower Over Time run is 56.52% faster than Faster Over Time run.
  • Slower Over Time run is 380.09% slower than Faster With More CPU Cores run.
func BenchmarkSlowerOverTime_run(b *testing.B) {
	for i := 0; i < b.N; i++ {
		time.Sleep(time.Duration(i/50) * time.Nanosecond)
	}
}

Slower Over Time run

ns/op ops/sec B/op allocs/op MB/s
18886.59 1219321 0.0 0 0.0
By Run Count
By CPU Core Count

Full Benchmark Code

func BenchmarkSlowerOverTime_run(b *testing.B) {
	for i := 0; i < b.N; i++ {
		time.Sleep(time.Duration(i/50) * time.Nanosecond)
	}
}

func BenchmarkFasterOverTime_run(b *testing.B) {
	const maxDelay = 1000 // Maximum delay in nanoseconds
	for i := 0; i < b.N; i++ {
		// Calculate the sleep duration, ensuring it's never less than 0
		delay := maxDelay - i
		if delay < 0 {
			delay = 0
		}
		time.Sleep(time.Duration(delay) * time.Nanosecond)
	}
}

func BenchmarkFasterWithMoreCPUCores_run(b *testing.B) {
	done := make(chan bool)

	for i := 0; i < b.N; i++ {
		go func() {
			// Increase the workload inside the goroutine
			time.Sleep(10000000 * time.Nanosecond)

			done <- true
		}()
	}

	// Wait for all goroutines to finish
	for i := 0; i < b.N; i++ {
		<-done
	}
}

Full Benchmark Output

Implementation Function Runs CPU Core Count ns/op ops/sec B/op allocs/op MB/s
Faster Over Time run 1000 2 21513 46483.52159159578 0 0 0
Faster Over Time run 2000 2 10716 93318.4023889511 0 0 0
Faster Over Time run 3000 2 7118 140488.90137679124 0 0 0
Faster Over Time run 4000 2 5918 168976.00540723218 0 0 0
Faster Over Time run 5000 2 4389 227842.333105491 0 0 0
Faster Over Time run 6000 2 3605 277392.51040221914 0 0 0
Faster Over Time run 7000 2 3301 302938.50348379277 0 0 0
Faster Over Time run 8000 2 2738 365230.0949598247 0 0 0
Faster Over Time run 9000 2 2228 448833.0341113106 0 0 0
Faster Over Time run 10000 2 2406 415627.59767248546 0 0 0
Faster Over Time run 1000 8 22478 44487.94376723908 0 0 0
Faster Over Time run 2000 8 10786 92712.77582050806 0 0 0
Faster Over Time run 3000 8 8247 121256.21438098703 0 0 0
Faster Over Time run 4000 8 5330 187617.2607879925 0 0 0
Faster Over Time run 5000 8 4135 241837.96856106407 0 0 0
Faster Over Time run 6000 8 3910 255754.4757033248 0 0 0
Faster Over Time run 7000 8 2969 336813.7420006736 0 0 0
Faster Over Time run 8000 8 2787 358808.7549336204 0 0 0
Faster Over Time run 9000 8 2558 390930.41438623925 0 0 0
Faster Over Time run 10000 8 2259 442673.74944665784 0 0 0
Faster Over Time run 1000 16 23201 43101.59044868756 0 0 0
Faster Over Time run 2000 16 12660 78988.94154818325 0 0 0
Faster Over Time run 3000 16 7154 139781.9401733296 0 0 0
Faster Over Time run 4000 16 5510 181488.20326678766 0 0 0
Faster Over Time run 5000 16 4860 205761.316872428 0 0 0
Faster Over Time run 6000 16 3724 268528.46401718585 0 0 0
Faster Over Time run 7000 16 3366 297088.53238265 0 0 0
Faster Over Time run 8000 16 2597 385059.6842510589 0 0 0
Faster Over Time run 9000 16 2435 410677.6180698152 0 0 0
Faster Over Time run 10000 16 2088 478927.2030651341 0 0 0
Faster Over Time run 1000 1 783140 1276.9108971575963 0 0 0
Faster Over Time run 2000 1 391575 2553.7891847028027 0 0 0
Faster Over Time run 3000 1 258987 3861.1976662921306 0 0 0
Faster Over Time run 4000 1 196414 5091.28677181871 0 0 0
Faster Over Time run 5000 1 156735 6380.195872013271 0 0 0
Faster Over Time run 6000 1 131193 7622.357900192846 0 0 0
Faster Over Time run 7000 1 110328 9063.882242041911 0 0 0
Faster Over Time run 8000 1 97240 10283.833813245577 0 0 0
Faster Over Time run 9000 1 83292 12005.954953657014 0 0 0
Faster Over Time run 10000 1 70372 14210.197237537657 0 0 0
Faster Over Time run 1000 4 21770 45934.77262287552 0 0 0
Faster Over Time run 2000 4 11924 83864.47500838645 0 0 0
Faster Over Time run 3000 4 7230 138312.58644536653 0 0 0
Faster Over Time run 4000 4 6232 160462.13093709885 0 0 0
Faster Over Time run 5000 4 4629 216029.37999567942 0 0 0
Faster Over Time run 6000 4 3777 264760.39184537996 0 0 0
Faster Over Time run 7000 4 3168 315656.56565656565 0 0 0
Faster Over Time run 8000 4 2708 369276.2186115214 0 0 0
Faster Over Time run 9000 4 2402 416319.73355537053 0 0 0
Faster Over Time run 10000 4 2277 439174.3522178305 0 0 0
Faster Over Time run 1000 32 20435 48935.649620748714 0 0 0
Faster Over Time run 2000 32 10922 91558.32265152903 0 0 0
Faster Over Time run 3000 32 8051 124208.17289777668 0 0 0
Faster Over Time run 4000 32 6104 163826.998689384 0 0 0
Faster Over Time run 5000 32 4241 235793.4449422306 0 0 0
Faster Over Time run 6000 32 3721 268744.96103198064 0 0 0
Faster Over Time run 7000 32 3235 309119.0108191654 0 0 0
Faster Over Time run 8000 32 2674 373971.5781600598 0 0 0
Faster Over Time run 9000 32 2301 434593.654932638 0 0 0
Faster Over Time run 10000 32 2191 456412.59698767686 0 0 0
Faster With More CPU Cores run 1000 1 11166 89557.58552749419 627 3 0
Faster With More CPU Cores run 2000 1 6862 145730.10784027982 613 3 0
Faster With More CPU Cores run 3000 1 4469 223763.70552696352 613 3 0
Faster With More CPU Cores run 4000 1 4030 248138.95781637717 608 3 0
Faster With More CPU Cores run 5000 1 3127 319795.33098816755 607 3 0
Faster With More CPU Cores run 6000 1 3523 283848.9923360772 639 3 0
Faster With More CPU Cores run 7000 1 3477 287604.25654299685 602 3 0
Faster With More CPU Cores run 8000 1 3336 299760.1918465228 616 3 0
Faster With More CPU Cores run 9000 1 3225 310077.51937984495 611 3 0
Faster With More CPU Cores run 10000 1 3272 305623.47188264056 635 3 0
Faster With More CPU Cores run 1000 4 10775 92807.42459396752 190 2 0
Faster With More CPU Cores run 2000 4 5491 182116.1901293025 157 2 0
Faster With More CPU Cores run 3000 4 3907 255950.8574353724 203 2 0
Faster With More CPU Cores run 4000 4 3067 326051.5161395501 195 2 0
Faster With More CPU Cores run 5000 4 2558 390930.41438623925 207 2 0
Faster With More CPU Cores run 6000 4 2300 434782.60869565216 187 2 0
Faster With More CPU Cores run 7000 4 1966 508646.998982706 192 2 0
Faster With More CPU Cores run 8000 4 1963 509424.35048395314 199 2 0
Faster With More CPU Cores run 9000 4 1782 561167.2278338945 155 2 0
Faster With More CPU Cores run 10000 4 1701 587889.4767783657 153 2 0
Faster With More CPU Cores run 1000 8 10801 92584.01999814832 193 2 0
Faster With More CPU Cores run 2000 8 5853 170852.55424568598 176 2 0
Faster With More CPU Cores run 3000 8 4143 241370.9872073377 165 2 0
Faster With More CPU Cores run 4000 8 3198 312695.4346466542 189 2 0
Faster With More CPU Cores run 5000 8 2767 361402.2406938923 189 2 0
Faster With More CPU Cores run 6000 8 2450 408163.2653061224 177 2 0
Faster With More CPU Cores run 7000 8 2225 449438.202247191 194 2 0
Faster With More CPU Cores run 8000 8 2107 474608.44803037494 188 2 0
Faster With More CPU Cores run 9000 8 1931 517866.39047125843 168 2 0
Faster With More CPU Cores run 10000 8 1765 566572.23796034 188 2 0
Faster With More CPU Cores run 1000 2 10879 91920.21325489476 194 2 0
Faster With More CPU Cores run 2000 2 5699 175469.3805930865 187 2 0
Faster With More CPU Cores run 3000 2 3962 252397.7788995457 180 2 0
Faster With More CPU Cores run 4000 2 3160 316455.69620253163 205 2 0
Faster With More CPU Cores run 5000 2 2814 355366.02700781805 186 2 0
Faster With More CPU Cores run 6000 2 2365 422832.9809725159 187 2 0
Faster With More CPU Cores run 7000 2 2035 491400.4914004914 156 2 0
Faster With More CPU Cores run 8000 2 1985 503778.3375314861 153 2 0
Faster With More CPU Cores run 9000 2 1775 563380.2816901408 172 2 0
Faster With More CPU Cores run 10000 2 1874 533617.9295624333 183 2 0
Faster With More CPU Cores run 1000 16 10801 92584.01999814832 197 2 0
Faster With More CPU Cores run 2000 16 5981 167196.12104999163 164 2 0
Faster With More CPU Cores run 3000 16 4270 234192.037470726 193 2 0
Faster With More CPU Cores run 4000 16 3564 280583.6139169473 195 2 0
Faster With More CPU Cores run 5000 16 3013 331895.1211417192 183 2 0
Faster With More CPU Cores run 6000 16 2772 360750.36075036076 189 2 0
Faster With More CPU Cores run 7000 16 2328 429553.264604811 185 2 0
Faster With More CPU Cores run 8000 16 2272 440140.8450704225 189 2 0
Faster With More CPU Cores run 9000 16 2054 486854.9172346641 174 2 0
Faster With More CPU Cores run 10000 16 2076 481695.5684007707 178 2 0
Faster With More CPU Cores run 1000 32 10776 92798.81217520416 211 2 0
Faster With More CPU Cores run 2000 32 6004 166555.6295802798 253 2 0
Faster With More CPU Cores run 3000 32 4259 234796.900680911 210 2 0
Faster With More CPU Cores run 4000 32 3430 291545.1895043732 170 2 0
Faster With More CPU Cores run 5000 32 3192 313283.20802005014 200 2 0
Faster With More CPU Cores run 6000 32 3005 332778.7021630616 199 2 0
Faster With More CPU Cores run 7000 32 2755 362976.4065335753 190 2 0
Faster With More CPU Cores run 8000 32 2666 375093.7734433608 195 2 0
Faster With More CPU Cores run 9000 32 2592 385802.4691358025 194 2 0
Faster With More CPU Cores run 10000 32 2442 409500.4095004095 188 2 0
Slower Over Time run 1000 2 303.4 3295978.9057350038 0 0 0
Slower Over Time run 2000 2 430.9 2320724.065908564 0 0 0
Slower Over Time run 3000 2 436.8 2289377.2893772894 0 0 0
Slower Over Time run 4000 2 1097 911577.0282588878 0 0 0
Slower Over Time run 5000 2 4091 244439.01246638963 0 0 0
Slower Over Time run 6000 2 5633 177525.29735487307 0 0 0
Slower Over Time run 7000 2 7464 133976.4201500536 0 0 0
Slower Over Time run 8000 2 8430 118623.96204033215 0 0 0
Slower Over Time run 9000 2 10253 97532.42953281966 0 0 0
Slower Over Time run 10000 2 9841 101615.689462453 0 0 0
Slower Over Time run 1000 8 386.6 2586652.8711846867 0 0 0
Slower Over Time run 2000 8 306.7 3260515.1613955004 0 0 0
Slower Over Time run 3000 8 308.9 3237293.622531564 0 0 0
Slower Over Time run 4000 8 1357 736919.6757553427 0 0 0
Slower Over Time run 5000 8 4013 249190.13207077 0 0 0
Slower Over Time run 6000 8 5634 177493.7877174299 0 0 0
Slower Over Time run 7000 8 7613 131354.26244581636 0 0 0
Slower Over Time run 8000 8 9025 110803.32409972299 0 0 0
Slower Over Time run 9000 8 9824 101791.53094462541 0 0 0
Slower Over Time run 10000 8 9866 101358.19987837016 0 0 0
Slower Over Time run 1000 16 243.4 4108463.4346754313 0 0 0
Slower Over Time run 2000 16 345.5 2894356.005788712 0 0 0
Slower Over Time run 3000 16 348.2 2871912.693854107 0 0 0
Slower Over Time run 4000 16 1421 703729.7677691766 0 0 0
Slower Over Time run 5000 16 3607 277238.7025228722 0 0 0
Slower Over Time run 6000 16 5583 179115.17105498837 0 0 0
Slower Over Time run 7000 16 7400 135135.13513513515 0 0 0
Slower Over Time run 8000 16 8352 119731.80076628353 0 0 0
Slower Over Time run 9000 16 8833 113211.81931393637 0 0 0
Slower Over Time run 10000 16 10838 92267.94611551947 0 0 0
Slower Over Time run 1000 1 276.8 3612716.76300578 0 0 0
Slower Over Time run 2000 1 253.3 3947887.8799842084 0 0 0
Slower Over Time run 3000 1 264 3787878.787878788 0 0 0
Slower Over Time run 4000 1 253.2 3949447.077409163 0 0 0
Slower Over Time run 5000 1 261.3 3827018.7523918864 0 0 0
Slower Over Time run 6000 1 68223 14657.813347404834 0 0 0
Slower Over Time run 7000 1 139562 7165.27421504421 0 0 0
Slower Over Time run 8000 1 193340 5172.235440157236 0 0 0
Slower Over Time run 9000 1 229041 4366.030536017569 0 0 0
Slower Over Time run 10000 1 261809 3819.578394936767 0 0 0
Slower Over Time run 1000 32 244.4 4091653.0278232405 0 0 0
Slower Over Time run 2000 32 298.3 3352329.869259135 0 0 0
Slower Over Time run 3000 32 318.1 3143665.513989311 0 0 0
Slower Over Time run 4000 32 1534 651890.482398957 0 0 0
Slower Over Time run 5000 32 3458 289184.4997108155 0 0 0
Slower Over Time run 6000 32 6108 163719.71185330715 0 0 0
Slower Over Time run 7000 32 7482 133654.10318096765 0 0 0
Slower Over Time run 8000 32 7921 126246.68602449185 0 0 0
Slower Over Time run 9000 32 9257 108026.35843145728 0 0 0
Slower Over Time run 10000 32 9482 105462.98249314491 0 0 0
Slower Over Time run 1000 4 326.5 3062787.136294028 0 0 0
Slower Over Time run 2000 4 350.9 2849814.7620404675 0 0 0
Slower Over Time run 3000 4 392 2551020.4081632653 0 0 0
Slower Over Time run 4000 4 1497 668002.672010688 0 0 0
Slower Over Time run 5000 4 4455 224466.8911335578 0 0 0
Slower Over Time run 6000 4 6306 158579.1309863622 0 0 0
Slower Over Time run 7000 4 7491 133493.52556401014 0 0 0
Slower Over Time run 8000 4 9034 110692.93779056896 0 0 0
Slower Over Time run 9000 4 9581 104373.23870159691 0 0 0
Slower Over Time run 10000 4 11090 90171.32551848512 0 0 0