<commit_before><?php

namespace BRS\PerformanceDiff;
use BRS\PerformanceDiff\Test;


define('BRS_PERFDIFF_CLASSES_DIR', dirname(__FILE__));
define('BRS_PERFDIFF_PACKAGE_DIR', dirname(BRS_PERFDIFF_CLASSES_DIR));
define('BRS_PERFDIFF_RESULTS_DIR', BRS_PERFDIFF_PACKAGE_DIR.DIRECTORY_SEPARATOR.'results');

class Executor {
	
	const TARE     = 1;
	const PROGRESS = 2;
	
	private static $min_it_rerun = 1;
	private static $max_it_rerun = 10;
	
	private static $min_mod_loops = 1;
	private static $max_mod_loops = 100;
	
	/**
	 * @var unknown DESCRIPTION
	 * @see setPrepCallback()
	 * @see execute()
	 */
	private $mod_loops        = 1;
	private $current_mod_loop = 0;
	
	private $flags = FALSE;
	
	private $name       = '';
	private $iterations = 0;
	private $iteration_rerun = 1;
	private $current_test_index = NULL;
	
	private $payload = NULL;
	
	private $tests = array();
	
	private $executing = FALSE;
	
	private $log_file = NULL;
	
	function __construct($name, $iterations, $flags) {
		
		$this->name       = $name;
		$this->iterations = $iterations;
		
		$this->flags = $flags;
	}
	
	public function log($file_name) {
		$results = $this->getResults();
		
		if(!empty($results)) {
			
			$export = '<?php return '.var_export($this->getResults(),true).';';
			
			if(!preg_match('/\.php$/i', $log_file)) {
				$file_name .= '.php';
			}
			
			$file_name = BRS_PERFDIFF_RESULTS_DIR.DIRECTORY_SEPARATOR.$file_name;
			
			if(file_put_contents($file_name, $export)) {
				return $file_name;
			}
		}
		
		return FALSE;
	}
	
	public function setRerun($times = 1) {
		if(!$this->executing) {
			
			$this->iteration_rerun = max(
				Executor::$min_it_rerun,
				min(
					Executor::$max_it_rerun,
					(int) $times
				)
			);
			
			return TRUE;
		}
		
		return FALSE;
	}<commit_msg>Export as JSON.<commit_after><?php

namespace BRS\PerformanceDiff;
use BRS\PerformanceDiff\Test;


define('BRS_PERFDIFF_CLASSES_DIR', dirname(__FILE__));
define('BRS_PERFDIFF_PACKAGE_DIR', dirname(BRS_PERFDIFF_CLASSES_DIR));
define('BRS_PERFDIFF_RESULTS_DIR', BRS_PERFDIFF_PACKAGE_DIR.DIRECTORY_SEPARATOR.'results');

class Executor {
	
	const TARE     = 1;
	const PROGRESS = 2;
	
	private static $min_it_rerun = 1;
	private static $max_it_rerun = 10;
	
	private static $min_mod_loops = 1;
	private static $max_mod_loops = 100;
	
	/**
	 * @var unknown DESCRIPTION
	 * @see setPrepCallback()
	 * @see execute()
	 */
	private $mod_loops        = 1;
	private $current_mod_loop = 0;
	
	private $flags = FALSE;
	
	private $name       = '';
	private $iterations = 0;
	private $iteration_rerun = 1;
	private $current_test_index = NULL;
	
	private $payload = NULL;
	
	private $tests = array();
	
	private $executing = FALSE;
	
	private $log_file = NULL;
	
	function __construct($name, $iterations, $flags) {
		
		$this->name       = $name;
		$this->iterations = $iterations;
		
		$this->flags = $flags;
	}
	
	public function log($file_name) {
		$results = $this->getResults();
		
		if(!empty($results)) {
			
			$export = json_encode($this->getResults());
			
			if(!preg_match('/\.php$/i', $log_file)) {
				$file_name .= '.json';
			}
			
			$file_name = BRS_PERFDIFF_RESULTS_DIR.DIRECTORY_SEPARATOR.$file_name;
			
			if(file_put_contents($file_name, $export)) {
				return $file_name;
			}
		}
		
		return FALSE;
	}
	
	public function setRerun($times = 1) {
		if(!$this->executing) {
			
			$this->iteration_rerun = max(
				Executor::$min_it_rerun,
				min(
					Executor::$max_it_rerun,
					(int) $times
				)
			);
			
			return TRUE;
		}
		
		return FALSE;
	}
{'fraction_non_alphanumeric': 0.13866139508613387, 'fraction_numerical': 0.007907370799209263, 'mean_word_length': 3.4835443037974683, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 17, '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': '5127662', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1272, 'n_words': 244}