get()); function book_type_is_allowed_new($type) { $allowed_types = config('book.settings')->get('allowed_types'); return isset($allowed_types[$type]); } function book_type_is_allowed_old($type) { return in_array($type, config('book.settings')->get('allowed_types')); } function benchmark($function, $allowed_types, $iterations) { config('book.settings')->set('allowed_types', $allowed_types)->save(); // Ensure book.settings read is primed. config('book.settings')->get(); $start_time = microtime(1); for ($i = 0; $i < $iterations; $i ++) { $function('node'); $function('e'); } //at the end $cpu_time = microtime(1) - $start_time; $count = count($allowed_types); echo "Calling $function with $count allowed types takes $cpu_time seconds.\n"; } $iterations = 100000; $allowed_types = drupal_map_assoc(array( 'book' )); benchmark('book_type_is_allowed_old', $allowed_types, $iterations); benchmark('book_type_is_allowed_new', $allowed_types, $iterations); $allowed_types = drupal_map_assoc(array( 'book', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' )); benchmark('book_type_is_allowed_old', $allowed_types, $iterations); benchmark('book_type_is_allowed_new', $allowed_types, $iterations);