class BENCHMARK_TABLE

(source code)

Description

Benchmark table

note
	description: "Benchmark table"

	author: "Finnian Reilly"
	copyright: "Copyright (c) 2001-2017 Finnian Reilly"
	contact: "finnian at eiffel hyphen loop dot com"

	license: "MIT license (See: en.wikipedia.org/wiki/MIT_License)"
	date: "2020-06-01 18:40:14 GMT (Monday 1st June 2020)"
	revision: "10"

deferred class
	BENCHMARK_TABLE

inherit
	EVOLICITY_SERIALIZEABLE_AS_XML
		redefine
			make_default
		end

	EL_BENCHMARK_ROUTINES

	EL_MODULE_HTML

	EL_MODULE_XML

feature {NONE} -- Initialization

	make (a_encoding_id: NATURAL; a_benchmark: like benchmark)
		require
			valid_zstring_benchmark: attached {ZSTRING_BENCHMARK} a_benchmark.zstring
			valid_string_32_benchmark: attached {STRING_32_BENCHMARK} a_benchmark.string_32
		do
			make_default
			if attached {MIXED_ENCODING_ZSTRING_BENCHMARK} a_benchmark.zstring then
				title := Title_mixed #$ [a_encoding_id]
			else
				title := Title_latin #$ [a_encoding_id]
			end
			benchmark := a_benchmark
			number_of_runs := benchmark.zstring.number_of_runs
			set_data_rows
		end

	make_default
		do
			Precursor
			create data_rows.make (19)
			create title.make_empty
		end

feature -- Access

	benchmark: TUPLE [zstring, string_32: STRING_BENCHMARK]

	data_rows: EL_ZSTRING_LIST

	number_of_runs: INTEGER

	title: ZSTRING

feature {NONE} -- Implementation

	append_to_row (row: like Html_row; index: INTEGER)
		deferred
		end

	column_title: STRING
		deferred
		end

	next_table_id: INTEGER_REF
		do
			Table_id.set_item (Table_id.item + 1)
			Result := Table_id.twin
		end

	relative_percentage_at_index (index: INTEGER): INTEGER
		local
			a, b: DOUBLE
		do
			a := test_result (benchmark.zstring, index)
			b := test_result (benchmark.string_32, index)
			Result := relative_percentage (a, b)
		end

	set_data_rows
		do
			across sorted_indices as index loop
				Html_row.wipe_out
				append_to_row (Html_row, index.item)
				data_rows.extend (Html_row.twin)
			end
		end

	sorted_indices: EL_ARRAYED_LIST [INTEGER]
		do
			create Result.make_from_list (1 |..| test_count)
			Result.order_by (agent relative_percentage_at_index, True)
		end

	test_count: INTEGER
		deferred
		end

	test_result (a_benchmark: STRING_BENCHMARK; index: INTEGER): DOUBLE
		deferred
		end

feature {NONE} -- Evolicity fields

	getter_function_table: like getter_functions
			--
		do
			create Result.make (<<
				["column_title", 		agent: STRING do Result := column_title end],
				["title", 				agent: ZSTRING do Result := title end],
				["data_rows", 			agent: EL_ZSTRING_LIST do Result := data_rows end],
				["table_id", 			agent next_table_id]
			>>)
		end

feature {NONE} -- Type definition

	Type_benchmark: STRING_BENCHMARK
		require
			never_called: False
		once
		end

feature {NONE} -- Constants

	Html_row: ZSTRING
		once
			create Result.make (100)
		end

	Table_id: INTEGER_REF
		once
			create Result
		end

	Template: STRING =
	"[
		<h3>$title</h3>
		<caption>Table $table_id (In ascending order of ZSTRING percentage)</caption>
		<table>
			<tr>
				<th width="40%">$column_title</th>
				<th>Input</th>
				<th>ZSTRING</th>
				<th>STRING_32</th>
			</tr>
		#across $data_rows as $row loop
			<tr>
				$row.item
			</tr>
		#end
		</table>
	]"

	Title_latin: ZSTRING
		once
			Result := "Pure Latin-%S Encoding"
		end

	Title_mixed: ZSTRING
		once
			Result := "Mixed Latin-%S and Unicode Encoding"
		end

end