Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save primiano/6dbe3929238063f7942f15c5078356d6 to your computer and use it in GitHub Desktop.
Save primiano/6dbe3929238063f7942f15c5078356d6 to your computer and use it in GitHub Desktop.
Another vector perftest using structs
$ sudo cpupower frequency-set -g powersave
$ sudo sh -c "echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo
$ for cpu in /sys/devices/system/cpu/cpu*; do for p in $(seq 4); do sudo sh -c "echo 1 > $cpu/cpuidle/state$p/disable"; done; do
####################
# Use emplace_back()
####################
$ perf stat out/offlnx/ctest
tcmalloc: large alloc 1600000000 bytes == 0x349af33da000 @
Performance counter stats for 'out/offlnx/ctest':
1263.947853 task-clock (msec) # 1.000 CPUs utilized
2 context-switches # 0.002 K/sec
0 cpu-migrations # 0.000 K/sec
391,576 page-faults # 0.310 M/sec
3,530,611,581 cycles # 2.793 GHz
2,427,142,407 stalled-cycles-frontend # 68.75% frontend cycles idle
<not supported> stalled-cycles-backend
2,865,689,418 instructions # 0.81 insns per cycle
# 0.85 stalled cycles per insn
485,486,138 branches # 384.103 M/sec
303,264 branch-misses # 0.06% of all branches
1.264433149 seconds time elapsed
#############################
# Use resize() + Initialize()
#############################
$ perf stat out/offlnx/ctest resize_and_initialize
tcmalloc: large alloc 1600000000 bytes == 0xbb728cf9000 @
Performance counter stats for 'out/offlnx/ctest resize_and_initialize':
1059.725647 task-clock (msec) # 0.999 CPUs utilized
2 context-switches # 0.002 K/sec
0 cpu-migrations # 0.000 K/sec
391,579 page-faults # 0.370 M/sec
2,899,437,341 cycles # 2.736 GHz
2,049,645,275 stalled-cycles-frontend # 70.69% frontend cycles idle
<not supported> stalled-cycles-backend
1,960,389,095 instructions # 0.68 insns per cycle
# 1.05 stalled cycles per insn
233,498,344 branches # 220.338 M/sec
278,474 branch-misses # 0.12% of all branches
1.060391691 seconds time elapsed
#include <stdio.h>
#include <vector>
#include "base/strings/string_number_conversions.h"
const int N = 100000000;
struct X {
X() {}
explicit X(int n) : x(n), y(n+1), w(n+2), h(n+3) {}
void Initialize(int n) { x = n; y = n + 1; w = n + 2; h = n + 3; }
int x;
int y;
int w;
int h;
};
int main(int argc, char** argv) {
std::vector<X> v1;
if (argc == 1) {
v1.reserve(N);
for (int i = 0; i < N; i++)
v1.emplace_back(i);
} else {
v1.resize(N);
for (int i = 0; i < N; i++)
v1[i].Init(i);
}
return v1.size();
}
$ cat out/offlnx/args.gn
is_component_build = false
is_debug = false
symbol_level=2
is_official_build = true
enable_nacl = false
allow_posix_link_time_opt = false
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/ctest/ctest.o.d -DV8_DEPRECATION_WARNINGS -DUSE_UDEV -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DDISABLE_NACL -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DOFFICIAL_BUILD -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -DCR_CLANG_REVISION=\"303910-1\" -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26 -I../.. -Igen -I../../build/linux/debian_jessie_amd64-sysroot/usr/include/glib-2.0 -I../../build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -fPIC -pipe -B../../third_party/binutils/Linux_x64/Release/bin -fcolor-diagnostics -m64 -march=x86-64 -pthread -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-address-of-packed-member -Wno-unused-lambda-capture -Wno-user-defined-warnings -O2 -fno-ident -fdata-sections -ffunction-sections -fomit-frame-pointer -g2 --sysroot=../../build/linux/debian_jessie_amd64-sysroot -fvisibility=hidden -Xclang -load -Xclang ../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-auto-raw-pointer -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -std=gnu++11 -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -c ../../ctest.cc -o obj/ctest/ctest.o
Raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment