<commit_before><?php

namespace Smuuf\Phpcb;

class ChaoticEngine implements IEngine {

	public function getEngineName() {
		return 'Chaotic Engine';
	}

	public function run($count, array $closures) {

		$totalCount = count($closures) * $count;

		$results = array();
		$remainingClosures = array();
		$closureCount = array();
		foreach ($closures as $closure) {

			$results[] = 0;
			$remainingClosures[] = true;
			$closureCount[] = 0;

		}

		$i = 0;
		while ($i++ - $totalCount) {

			$whichKey = array_rand($remainingClosures);

			$time = microtime(true);
			$closures[$whichKey]();
			$results[$whichKey] += microtime(true) - $time;

			if (++$closureCount[$whichKey] == $count) {
				unset($remainingClosures[$whichKey]);
			}<commit_msg>ChaoticEngine runs benchmarks in batches to decrease call overhead.<commit_after><?php

namespace Smuuf\Phpcb;

class ChaoticEngine implements IEngine {

	const BATCH_SIZE = 1000;

	public function getEngineName() {
		return 'Chaotic Engine';
	}

	public function run($count, array $closures) {

		$totalCount = count($closures) * $count;

		$results = array();
		$remainingClosures = array();
		$closureCount = array();
		foreach ($closures as $closure) {

			$results[] = 0;
			$remainingClosures[] = true;
			$closureCount[] = 0;

		}

		$i = 0;
		while ($i <= $totalCount) {

			$whichKey = array_rand($remainingClosures);

			$y = min(self::BATCH_SIZE, $count);

			$time = microtime(true);
			while ($y--) {
-				$closures[$whichKey]();
			}

			$results[$whichKey] += microtime(true) - $time;

			if (++$closureCount[$whichKey] == $count) {
				unset($remainingClosures[$whichKey]);
			}

			$i += self::BATCH_SIZE;
{'fraction_non_alphanumeric': 0.16467065868263472, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 4.018018018018018, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1765738', 'n_tokens_mistral': 678, 'n_tokens_neox': 564, 'n_words': 126}