diff --git a/.gitignore b/.gitignore
index 64d767b3b..5774bf11d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,6 +51,7 @@
 /rake.d/dependency.d
 /share/icons/*/*.h
 /src/*/qt_resources.cpp
+/src/benchmark/
 /src/common/common.h.gch
 /src/common/common_pch.h.[gp]ch
 /src/common/common_pch.h.pch-????????
diff --git a/Rakefile b/Rakefile
index 99311e46c..f471ad24d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -115,6 +115,8 @@ def setup_globals
   $unwrapped_po            = %{ca es eu it nl uk pl sr_RS@latin tr}
   $po_multiple_sources     = %{sv}
 
+  $benchmark_sources       = FileList["src/benchmark/*.cpp"].to_a if c?(:GOOGLE_BENCHMARK)
+
   cflags_common            = "-Wall -Wno-comment -Wfatal-errors #{c(:WLOGICAL_OP)} #{c(:WNO_MISMATCHED_TAGS)} #{c(:WNO_SELF_ASSIGN)} #{c(:QUNUSED_ARGUMENTS)}"
   cflags_common           += " #{c(:WNO_INCONSISTENT_MISSING_OVERRIDE)} #{c(:WNO_POTENTIALLY_EVALUATED_EXPRESSION)}"
   cflags_common           += " #{c(:OPTIMIZATION_CFLAGS)} -D_FILE_OFFSET_BITS=64"
@@ -211,6 +213,8 @@ def define_default_task
   # needed for running the tests.
   targets << "apps:tools:ebml_validator" if c(:host) == c(:build)
 
+  targets << "src/benchmark/benchmark" if c?(:GOOGLE_BENCHMARK) && !$benchmark_sources.empty?
+
   task :default => targets do
     puts "Done. Enjoy :)"
   end
@@ -843,6 +847,7 @@ task :clean do
     src/*/qt_resources.cpp
     src/info/ui/*.h
     src/mkvtoolnix-gui/forms/**/*.h
+    src/benchmark/benchmark
     tests/unit/all
     tests/unit/merge/merge
     tests/unit/propedit/propedit
@@ -1057,6 +1062,19 @@ if $build_mkvtoolnix_gui
     create
 end
 
+#
+# benchmark
+#
+
+if c?(:GOOGLE_BENCHMARK) && !$benchmark_sources.empty?
+  Application.new("src/benchmark/benchmark").
+    description("Build the benchmark executable").
+    aliases(:benchmark, :bench).
+    sources($benchmark_sources).
+    libraries($common_libs, :benchmark).
+    create
+end
+
 #
 # Applications in src/tools
 #
diff --git a/ac/benchmark.m4 b/ac/benchmark.m4
new file mode 100644
index 000000000..61b19484e
--- /dev/null
+++ b/ac/benchmark.m4
@@ -0,0 +1,16 @@
+AC_DEFUN([AX_GOOGLE_BENCHMARK],[
+  GOOGLE_BENCHMARK=yes
+
+  CPPFLAGS_SAVED="$CPPFLAGS"
+  AC_LANG_PUSH(C++)
+
+  AC_CHECK_LIB([benchmark],[main],[true],[GOOGLE_BENCHMARK=no])
+  AC_CHECK_HEADERS([benchmark/benchmark.h],[true],[GOOGLE_BENCHMARK=no])
+
+  AC_LANG_POP
+  CPPFLAGS="$CPPFLAGS_SAVED"
+
+  AC_SUBST(GOOGLE_BENCHMARK)
+])
+
+AX_GOOGLE_BENCHMARK
diff --git a/build-config.in b/build-config.in
index d52318d66..26963657c 100644
--- a/build-config.in
+++ b/build-config.in
@@ -87,6 +87,7 @@ EGREP = @EGREP@
 EXTRA_CFLAGS = @EXTRA_CFLAGS@
 EXTRA_LDFLAGS = @EXTRA_LDFLAGS@
 FSTACK_PROTECTOR = @FSTACK_PROTECTOR@
+GOOGLE_BENCHMARK = @GOOGLE_BENCHMARK@
 GTEST_TYPE = @GTEST_TYPE@
 LDFLAGS_RPATHS = @LDFLAGS_RPATHS@
 FLAC_LIBS = @FLAC_LIBS@
diff --git a/configure.ac b/configure.ac
index 6e6285249..de594e5cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,7 @@ m4_include(ac/ax_boost_system.m4)
 m4_include(ac/ax_boost_date_time.m4)
 m4_include(ac/boost.m4)
 m4_include(ac/gtest.m4)
+m4_include(ac/benchmark.m4)
 m4_include(ac/pandoc.m4)
 m4_include(ac/ax_docbook.m4)
 m4_include(ac/tiocgwinsz.m4)