diff --git a/python/dune/codegen/sumfact/autotune.py b/python/dune/codegen/sumfact/autotune.py
index e7a31f137869571f36e7f62febfa188f57a0fef4..f5a259d761ffde766e35e2e588113cf499c1e460 100644
--- a/python/dune/codegen/sumfact/autotune.py
+++ b/python/dune/codegen/sumfact/autotune.py
@@ -176,6 +176,10 @@ def write_setup_code(sf, filename, define_thetas=True):
 def generate_standalone_code_google_benchmark(sf, filename):
     delete_cache_items("kernel_default")
 
+    # Turn off opcounting
+    opcounting = get_option("opcounter")
+    set_option("opcounter", False)
+
     # Extract sum factorization kernel
     from dune.codegen.pdelab.localoperator import extract_kernel_from_cache
     knl = realize_sumfact_kernel_function(sf)
@@ -185,10 +189,6 @@ def generate_standalone_code_google_benchmark(sf, filename):
     first_line = knl.member.lines[0]
     arguments = first_line[first_line.find("(") + 1:first_line.find(")")]
 
-    # Turn off opcounting
-    opcounting = get_option("opcounter")
-    set_option("opcounter", False)
-
     with open(filename, "w") as f:
         f.writelines(["// {}".format(first_line),
                       "\n",
@@ -241,15 +241,15 @@ def generate_standalone_code_google_benchmark(sf, filename):
 def generate_standalone_code(sf, filename):
     delete_cache_items("kernel_default")
 
+    # Turn off opcounting
+    opcounting = get_option("opcounter")
+    set_option("opcounter", False)
+
     # Extract sum factorization kernel
     from dune.codegen.pdelab.localoperator import extract_kernel_from_cache
     knl = realize_sumfact_kernel_function(sf)
     first_line = knl.member.lines[0]
 
-    # Turn off opcounting
-    opcounting = get_option("opcounter")
-    set_option("opcounter", False)
-
     with open(filename, "w") as f:
         f.writelines(["// {}".format(first_line),
                       "\n",