Skip to content

Instantly share code, notes, and snippets.

@Alexhuszagh
Created August 4, 2019 15:30
Show Gist options
  • Save Alexhuszagh/f9929e7d8e0277aa1281f511a841a167 to your computer and use it in GitHub Desktop.
Save Alexhuszagh/f9929e7d8e0277aa1281f511a841a167 to your computer and use it in GitHub Desktop.
Benchmark Results for rust-memchr

Results

These results were run on an x86_64 Intel CPU to profile the performance of BurntSushi's memchr crate.

name unit rust libc fallback naive
memchr1/huge/never μs 10.957 10.817 48.203 356.29
memchr1/huge/rare μs 12.678 12.136 49.868 361.04
memchr1/huge/uncommon μs 107.72 98.615 203.96 416.35
memchr1/huge/common μs 285.06 368.47 846.11 702.37
memchr1/small/never ns 11.446 11.264 53.071 410.55
memchr1/small/rare ns 18.311 16.299 60.124 409.72
memchr1/small/uncommon ns 59.011 59.781 102.29 414.94
memchr1/small/common ns 288.42 295.03 301.34 491.56
memchr1/tiny/never ns 5.0710 4.7868 9.4404 44.495
memchr1/tiny/rare ns 7.7046 8.5632 13.021 46.659
memchr1/tiny/uncommon ns 25.900 24.364 39.374 55.385
memchr1/tiny/common ns 61.185 68.426 67.397 71.847
memchr1/empty/never ns 1.1142 2.5708 3.0289 3.5119
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')
rust = np.array([10.957, 12.678, 107.72, 285.06, 11.446, 18.311, 59.011, 288.42, 5.0710, 7.7046, 25.900, 61.185, 1.1142])
libc = np.array([10.817, 12.136, 98.615, 368.47, 11.264, 16.299, 59.781, 295.03, 4.7868, 8.5632, 24.364, 68.426, 2.5708])
fallback = np.array([48.203, 49.868, 203.96, 846.11, 53.071, 60.124, 102.29, 301.34, 9.4404, 13.021, 39.374, 67.397, 3.0289])
naive = np.array([356.29, 361.04, 416.35, 702.37, 410.55, 409.72, 414.94, 491.56, 44.495, 46.659, 55.385, 71.847, 3.5119])
index = ["huge/never (μs)", "huge/rare (μs)", "huge/uncommon (μs)", "huge/common (μs)", "small/never (ns)", "small/rare (ns)", "small/uncommon (ns)", "small/common (ns)", "tiny/never (ns)", "tiny/rare (ns)", "tiny/uncommon (ns)", "tiny/common (ns)", "empty/never (ns)"]
df = pd.DataFrame({'rust': rust, 'libc': libc, 'fallback': fallback, 'naive': naive}, index = index, columns=['rust', 'libc', 'fallback', 'naive'])
ax = df.plot.bar(rot=0, figsize=(16, 8), fontsize=14, color=['#E24A33', '#988ED5', '#348ABD', '#8ABD34'])
ax.set_yscale("log")
ax.set_title("memchr1")
ax.legend(loc=2, prop={'size': 14})
plt.xticks(rotation=45)
ax.figure.tight_layout()
plt.show()
name unit rust fallback naive
memchr2/huge/never μs 14.593 109.81 236.80
memchr2/huge/rare μs 19.814 117.84 240.70
memchr2/huge/uncommon μs 217.67 425.65 388.89
memchr2/huge/common μs 592.77 1607.6 1118.4
memchr2/small/never ns 16.824 126.98 273.1
memchr2/small/rare ns 33.084 138.15 270.09
memchr2/small/uncommon ns 146.85 226.89 288.63
memchr2/small/common ns 605.28 587.78 370.93
memchr2/tiny/never ns 6.6808 17.530 30.426
memchr2/tiny/rare ns 14.427 27.77 33.182
memchr2/tiny/uncommon ns 73.553 74.021 43.895
memchr2/empty/never ns 1.2716 3.1986 3.3616
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')
rust = np.array([14.593, 19.814, 217.67, 592.77, 16.824, 33.084, 146.85, 605.28, 6.6808, 14.427, 73.553, 1.2716])
fallback = np.array([109.81, 117.84, 425.65, 1607.6, 126.98, 138.15, 226.89, 587.78, 17.530, 27.77, 74.021, 3.1986])
naive = np.array([236.80, 240.70, 388.89, 1118.4, 273.1, 270.09, 288.63, 370.93, 30.426, 33.182, 43.895, 3.3616])
index = ["huge/never (μs)", "huge/rare (μs)", "huge/uncommon (μs)", "huge/common (μs)", "small/never (ns)", "small/rare (ns)", "small/uncommon (ns)", "small/common (ns)", "tiny/never (ns)", "tiny/rare (ns)", "tiny/uncommon (ns)", "empty/never (ns)"]
df = pd.DataFrame({'rust': rust, 'fallback': fallback, 'naive': naive}, index = index, columns=['rust', 'fallback', 'naive'])
ax = df.plot.bar(rot=0, figsize=(16, 8), fontsize=14, color=['#E24A33', '#348ABD', '#8ABD34'])
ax.set_yscale("log")
ax.set_title("memchr2")
ax.legend(loc=2, prop={'size': 14})
plt.xticks(rotation=45)
ax.figure.tight_layout()
plt.show()
name unit rust fallback naive
memchr3/huge/never μs 18.718 162.90 332.08
memchr3/huge/rare μs 25.664 173.87 337.07
memchr3/huge/uncommon μs 290.16 694.71 581.24
memchr3/huge/common μs 841.52 2335.9 1698.0
memchr3/small/never ns 21.926 199.05 382.96
memchr3/small/rare ns 46.59 216.28 376.17
memchr3/small/uncommon ns 220.43 392.96 407.55
memchr3/small/common ns 879.51 1035.8 525.44
memchr3/tiny/never ns 6.7064 24.503 41.457
memchr3/tiny/rare ns 25.857 44.448 45.944
memchr3/tiny/uncommon ns 103.79 130.45 62.810
memchr3/empty/never ns 1.2699 4.2200 3.1735
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')
rust = np.array([18.718, 25.664, 290.16, 841.52, 21.926, 46.59 , 220.43, 879.51, 6.7064, 25.857, 103.79, 1.2699])
fallback = np.array([162.90, 173.87, 694.71, 2335.9, 199.05, 216.28, 392.96, 1035.8, 24.503, 44.448, 130.45, 4.2200])
naive = np.array([332.08, 337.07, 581.24, 1698.0, 382.96, 376.17, 407.55, 525.44, 41.457, 45.944, 62.810, 3.1735])
index = ["huge/never (μs)", "huge/rare (μs)", "huge/uncommon (μs)", "huge/common (μs)", "small/never (ns)", "small/rare (ns)", "small/uncommon (ns)", "small/common (ns)", "tiny/never (ns)", "tiny/rare (ns)", "tiny/uncommon (ns)", "empty/never (ns)"]
df = pd.DataFrame({'rust': rust, 'fallback': fallback, 'naive': naive}, index = index, columns=['rust', 'fallback', 'naive'])
ax = df.plot.bar(rot=0, figsize=(16, 8), fontsize=14, color=['#E24A33', '#348ABD', '#8ABD34'])
ax.set_yscale("log")
ax.set_title("memchr3")
ax.legend(loc=2, prop={'size': 14})
plt.xticks(rotation=45)
ax.figure.tight_layout()
plt.show()

Details

The CPU info is dumped below:

processor : 0
vendor_id : GenuineIntel
cpu family  : 6
model   : 78
model name  : Intel(R) Core(TM) i7-6560U CPU @ 2.20GHz
stepping  : 3
microcode : 0xcc
cpu MHz   : 3104.179
cache size  : 4096 KB
physical id : 0
siblings  : 4
core id   : 0
cpu cores : 2
apicid    : 0
initial apicid  : 0
fpu   : yes
fpu_exception : yes
cpuid level : 22
wp    : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs    : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds
bogomips  : 4416.00
clflush size  : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment