Skip to content

Instantly share code, notes, and snippets.

@dunnousername
Created December 21, 2018 22:35
Show Gist options
  • Save dunnousername/214ab867a5b57fd35a7ef22b9eee18cd to your computer and use it in GitHub Desktop.
Save dunnousername/214ab867a5b57fd35a7ef22b9eee18cd to your computer and use it in GitHub Desktop.
AWS Graviton ARM vs x86 GMP benchmarks
#include <iostream>
#include <chrono>
#include <cstdlib>
#include <gmpxx.h>
using namespace std;
static gmp_randclass rand0 (gmp_randinit_default);
static volatile bool _noopt;
long long floattest(int length) {
mpf_class a(0, length);
mpf_class b(0, length);
a = rand0.get_f();
b = rand0.get_f();
auto start = chrono::high_resolution_clock::now();
mpf_class c = a * b;
auto finish = chrono::high_resolution_clock::now();
_noopt = c > a;
auto ns = chrono::duration_cast<chrono::nanoseconds>(finish-start).count();
//cout << "float of length " << length << " bits took " << ns / 1000 << "us\n";
return ns;
}
long long inttest(int length) {
mpz_class a(0);
mpz_class b(0);
a = rand0.get_z_bits(length);
b = rand0.get_z_bits(length);
auto start = chrono::high_resolution_clock::now();
mpz_class c = a * b;
auto finish = chrono::high_resolution_clock::now();
_noopt = c > a;
auto ns = chrono::duration_cast<chrono::nanoseconds>(finish-start).count();
//cout << "int of length " << length << " bits took " << ns / 1000 << "us\n";
return ns;
}
int main(int argc, char **argv) {
int length = 16384;
if (argc > 1) {
length = atoi(argv[1]);
}
double floats = 0;
double ints = 0;
for (auto i = 0; i < 1000; i++) {
floats += floattest(length);
ints += inttest(length);
}
floats /= 1000.0;
ints /= 1000.0;
cout << "average float multiplication took " << floats << "ns (" << floats / 1000 << "us) at " << length << " bits\n";
cout << "average int multiplication took " << floats << "ns (" << ints / 1000 << "us) at " << length << " bits\n";
return 0;
}
On x86, Dell Inspiron laptop with Intel Core i5 7th gen:
-- BEGIN --
$ ./gmpmathtest 65536
average float multiplication took 172790ns (172.79us) at 65536 bits
average int multiplication took 172790ns (171.656us) at 65536 bits
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
Stepping: 9
CPU MHz: 1160.940
CPU max MHz: 2500.0000
CPU min MHz: 800.0000
BogoMIPS: 4992.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
NUMA node0 CPU(s): 0-3
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 retpoline intel_pt rsb_ctxsw spec_ctrl tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp
-- END --
On AWS Graviton ARM, a1.large:
-- BEGIN --
$ ./gmpmathtest 65536
average float multiplication took 411859ns (411.859us) at 65536 bits
average int multiplication took 411859ns (406.372us) at 65536 bits
$ lscpu
Architecture: aarch64
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: ARM
Model: 3
Model name: Cortex-A72
Stepping: r0p3
BogoMIPS: 166.66
L1d cache: 32K
L1i cache: 48K
L2 cache: 2048K
NUMA node0 CPU(s): 0,1
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
-- END --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment