<commit_before>import fs from 'graceful-fs'
import evaluate from '../src/lib/evaluate'
import endsWith from 'lodash/string/endsWith'
import junk from 'junk'
import nom from 'nomnom'
import ms from 'pretty-ms'
import range from 'lodash/utility/range'
import size from 'lodash/collection/size'
import sparkly from 'sparkly'
import sum from 'lodash/collection/sum'
import loadArea from '../bin/lib/load-area'

function now(other=[]) {
	let time = process.hrtime(other)
	return time[0] * 1e3 + time[1] / 1e6
}

function loadStudents(dir) {
	return fs.readdirSync(dir)
		.filter(name => !endsWith(name, '.ip'))
		.filter(junk.not)
		.map(path => dir + path)
		.map(path => fs.readFileSync(path, 'utf-8'))
		.map(JSON.parse)
}

function benchmark({runs, graph}) {
	loadStudents('./test/example-students/')
		.forEach(({courses=[], overrides={}, areas=[]}) => {
			areas.forEach(areaInfo => {
				console.log(`the '${areaInfo.name}' ${areaInfo.type} (${areaInfo.revision})`)
				let areaData = loadArea(areaInfo)
				let times = range(runs).map(() => {
					const start = process.hrtime()
					evaluate({courses, overrides}, areaData)
					return now(start)
				})

				const avg = sum(times) / size(times)
				if (graph) {
					console.log(`  ${sparkly(times)}`)
				}
				console.log(`  average time: ${ms(avg)} (over ${runs} runs)\n`)
			})
		})
}

function cli() {
	const args = nom
		.script('students-benchmark')
		.option('runs', {
			string: '-r, --runs',
			metavar: 'COUNT',
			default: 50,
		})
		.option('graph', {
			flag: true,
			default: true,
		})
		.option('debug', {flag: true})
		.parse()
<commit_msg>fix students-benchmark<commit_after>import fs from 'graceful-fs'
import evaluate from '../src/area-tools/evaluate'
import endsWith from 'lodash/string/endsWith'
import junk from 'junk'
import nom from 'nomnom'
import ms from 'pretty-ms'
import range from 'lodash/utility/range'
import size from 'lodash/collection/size'
import sparkly from 'sparkly'
import sum from 'lodash/collection/sum'
import loadArea from '../bin/lib/load-area'

function now(other=[]) {
	let time = process.hrtime(other)
	return time[0] * 1e3 + time[1] / 1e6
}

function loadStudents(dir) {
	return fs.readdirSync(dir)
		.filter(name => !endsWith(name, '.ip'))
		.filter(junk.not)
		.map(path => dir + path)
		.map(path => fs.readFileSync(path, 'utf-8'))
		.map(JSON.parse)
}

async function benchmark({runs, graph}) {
	for (const {courses=[], overrides={}, areas=[]} of loadStudents('./test/example-students/')) {
		for (const areaInfo of areas) {
			console.log(`the '${areaInfo.name}' ${areaInfo.type} (${areaInfo.revision})`)
			const areaData = await loadArea(areaInfo)  // eslint-disable-line babel/no-await-in-loop

			let times = range(runs).map(() => {
				const start = process.hrtime()
				evaluate({courses, overrides}, areaData)
				return now(start)
			})

			const avg = sum(times) / size(times)
			if (graph) {
				console.log(`  ${sparkly(times)}`)
			}
			console.log(`  average time: ${ms(avg)} (over ${runs} runs)\n`)
		}
	}
}

function cli() {
	const args = nom
		.script('students-benchmark')
		.option('runs', {
			string: '-r, --runs',
			metavar: 'COUNT',
			default: 50,
		})
		.option('graph', {
			flag: true,
			default: true,
		})
		.option('debug', {flag: true})
		.parse()

{'fraction_non_alphanumeric': 0.1798298906439854, 'fraction_numerical': 0.0054678007290400975, 'mean_word_length': 3.7793904208998548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7198608', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1183, 'n_words': 278}