@@ -2,6 +2,8 @@ import React from "react";
22import * as d3 from "d3" ;
33
44import { join as joinOnProperty } from "./util" ;
5+ import { barComparisonGraph } from './bar-comparison-graph' ;
6+ import { positiveNegativeBarGraph } from './positive-negative-bar-graph' ;
57
68export enum BenchmarkKind {
79 Memory = "memory" ,
@@ -21,23 +23,39 @@ export interface MemoryBenchmarkResult {
2123}
2224
2325const dataMaster : BenchmarkResult [ ] = [ { "benchmarkName" :"./memory_benchmarks/class_creation.lua" , "categories" :{ "garbage" :8.5390625 , "totalMemory" :917.02734375 } , "kind" :"memory" } , { "benchmarkName" :"./memory_benchmarks/array_every.lua" , "categories" :{ "garbage" :128.5390625 , "totalMemory" :129.08203125 } , "kind" :"memory" } , { "benchmarkName" :"./memory_benchmarks/array_push.lua" , "categories" :{ "garbage" :4.625 , "totalMemory" :132.4296875 } , "kind" :"memory" } , { "benchmarkName" :"./memory_benchmarks/graph_cylce.lua" , "categories" :{ "garbage" :172575.6484375 , "totalMemory" :172590.37109375 } , "kind" :"memory" } , { "benchmarkName" :"./memory_benchmarks/array_concat.lua" , "categories" :{ "garbage" :58287.7734375 , "totalMemory" :58417.96875 } , "kind" :"memory" } ] ;
24- const dataCommit : BenchmarkResult [ ] = [ { "categories" :{ "garbage" :5.5390625 , "totalMemory" :917.02734375 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/class_creation.lua" } , { "categories" :{ "garbage" :128 .5390625, "totalMemory" :129.08203125 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/array_every.lua" } , { "categories" :{ "garbage" :3.625 , "totalMemory" :132.4296875 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/array_push.lua" } , { "categories" :{ "garbage" :172572.8359375 , "totalMemory" :172587.55078125 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/graph_cylce.lua" } , { "categories" :{ "garbage" :48287.7734375 , "totalMemory" :58417.96875 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/array_concat.lua" } ] ;
26+ const dataCommit : BenchmarkResult [ ] = [ { "categories" :{ "garbage" :5.5390625 , "totalMemory" :917.02734375 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/class_creation.lua" } , { "categories" :{ "garbage" :168 .5390625, "totalMemory" :129.08203125 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/array_every.lua" } , { "categories" :{ "garbage" :3.625 , "totalMemory" :132.4296875 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/array_push.lua" } , { "categories" :{ "garbage" :172572.8359375 , "totalMemory" :172587.55078125 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/graph_cylce.lua" } , { "categories" :{ "garbage" :48287.7734375 , "totalMemory" :58417.96875 } , "kind" :"memory" , "benchmarkName" :"./memory_benchmarks/array_concat.lua" } ] ;
2527
2628const matchedBenchmarks = joinOnProperty ( dataMaster , dataCommit , bm => bm . benchmarkName ) ;
2729
2830const formatBenchmarkName = ( benchmarkName : string ) => benchmarkName . replace ( ".lua" , "" ) . split ( "/" ) . pop ( ) ! ;
2931
32+ // Comparison data master garbage created vs commit garbate created (ABSOLUTE)
3033const generatedGarbageData = matchedBenchmarks . map ( bm => ( {
3134 name : formatBenchmarkName ( bm . left ?. benchmarkName ?? bm . right ?. benchmarkName ! ) ,
3235 oldValue : bm . left ?. categories [ MemoryBenchmarkCategory . Garbage ] ?? 0 ,
3336 newValue : bm . right ?. categories [ MemoryBenchmarkCategory . Garbage ] ?? 0
3437} ) ) ;
3538
36- const GRAPH_WIDTH = 1000 ;
37- const GRAPH_HEIGHT = 300 ;
38- const GRAPH_MARGIN = { left : 50 , top : 5 , right : 1 } ;
3939
40- let node : SVGSVGElement | null = null ;
40+ let garbageCreatedComparisonSvg : SVGSVGElement ;
41+ const garbageCreatedComparisonGraphWidth = 1000 ;
42+ const garbageCreatedComparisonGraphHeight = 300 ;
43+
44+ // Comparison data master garbage created vs commit garbate created (ABSOLUTE)
45+ const generatedGarbageChangeData = matchedBenchmarks . map ( bm => {
46+ const oldValue = bm . left ?. categories [ MemoryBenchmarkCategory . Garbage ] ! ;
47+ const newValue = bm . right ?. categories [ MemoryBenchmarkCategory . Garbage ] ! ;
48+
49+ return {
50+ name : formatBenchmarkName ( bm . left ?. benchmarkName ?? bm . right ?. benchmarkName ! ) ,
51+ value : 100 * ( newValue - oldValue ) / oldValue
52+ } ;
53+ } ) ;
54+
55+
56+ let garbageCreatedChangeSvg : SVGSVGElement ;
57+ const garbageCreatedChangeGraphWidth = 1000 ;
58+ const garbageCreatedChangeGraphHeight = 300 ;
4159
4260export default class extends React . Component {
4361
@@ -50,88 +68,36 @@ export default class extends React.Component {
5068 }
5169
5270 draw ( ) {
53- const barMaxHeight = GRAPH_HEIGHT - 50 ;
54-
55- const xScale = d3 . scaleBand ( )
56- . domain ( generatedGarbageData . map ( bm => bm . name ) )
57- . range ( [ GRAPH_MARGIN . left , GRAPH_WIDTH - GRAPH_MARGIN . right ] ) ;
58-
59- const bandWidth = xScale . bandwidth ( ) ;
60- const barWidth = 25 ;
61-
62- const xAxis = d3 . axisBottom ( xScale ) ;
63-
64- d3 . select ( node )
65- . append ( "g" )
66- . attr ( "transform" , `translate(0, ${ barMaxHeight } )` )
67- . call ( xAxis ) ;
68-
69- const maxValue = d3 . max ( generatedGarbageData . map ( bm => Math . max ( bm . oldValue , bm . newValue ) ) ) ! ;
70- const maxAxisValue = Math . pow ( 10 , Math . ceil ( Math . log10 ( maxValue ) ) ) ;
71-
72- const yScale = d3 . scaleLog ( )
73- . domain ( [ 1 , maxAxisValue ] )
74- . range ( [ barMaxHeight - GRAPH_MARGIN . top , 0 ] ) ;
75-
76- const yAxis = d3 . axisLeft ( yScale ) ;
77-
78- d3 . select ( node )
79- . append ( "g" )
80- . attr ( "transform" , `translate(${ GRAPH_MARGIN . left } , ${ GRAPH_MARGIN . top } )` )
81- . call ( yAxis ) ;
82-
83- const entries = d3 . select ( node )
84- . selectAll ( 'rect' )
85- . data ( generatedGarbageData )
86- . enter ( ) ;
87-
88- entries
89- . append ( 'rect' )
90- . attr ( 'width' , barWidth )
91- . attr ( 'x' , d => xScale ( d . name ) ! + 0.5 * bandWidth - barWidth - 1 )
92- . attr ( 'height' , d => barMaxHeight - yScale ( d . oldValue ) )
93- . attr ( 'y' , d => yScale ( d . oldValue ) )
94- . style ( 'fill' , 'red' ) ;
95- //.style("stroke", "currentColor");
96-
97- entries
98- . append ( 'rect' )
99- . attr ( 'width' , barWidth )
100- . attr ( 'x' , d => xScale ( d . name ) ! + 0.5 * bandWidth + 1 )
101- . attr ( 'height' , d => barMaxHeight - yScale ( d . newValue ) )
102- . attr ( 'y' , d => yScale ( d . newValue ) )
103- . style ( 'fill' , 'blue' )
104- //.style("stroke", "currentColor");
105-
106- // Add legend
107- const legendEntries = [ [ "Master" , "red" ] , [ "Commit" , "blue" ] ] ;
108- const legend = d3 . select ( node )
109- . append ( "g" )
110- . attr ( "transform" , `translate(${ GRAPH_WIDTH - 100 * legendEntries . length - GRAPH_MARGIN . right } , ${ GRAPH_HEIGHT - 20 } )` ) ;
111-
112- legendEntries . forEach ( ( [ name , color ] , i ) => {
113- legend . append ( "rect" )
114- . attr ( "width" , 15 )
115- . attr ( "height" , 15 )
116- . attr ( "x" , 100 * i )
117- . style ( "fill" , color )
118- . style ( "stroke" , "currentColor" ) ;
119-
120- legend . append ( "text" )
121- . attr ( "x" , 100 * i + 20 )
122- . attr ( "y" , 13 )
123- //.attr("width", 80)
124- //.attr("height", 20)
125- . text ( name )
126- . attr ( "fill" , "currentColor" ) ;
127- } ) ;
71+ positiveNegativeBarGraph (
72+ d3 . select ( garbageCreatedChangeSvg ) ,
73+ generatedGarbageChangeData . sort ( ( a , b ) => a . value - b . value ) ,
74+ garbageCreatedChangeGraphWidth ,
75+ garbageCreatedChangeGraphHeight
76+ ) ;
77+
78+ barComparisonGraph (
79+ d3 . select ( garbageCreatedComparisonSvg ) ,
80+ generatedGarbageData ,
81+ garbageCreatedComparisonGraphWidth ,
82+ garbageCreatedComparisonGraphHeight
83+ ) ;
12884 }
12985
13086 render ( ) {
13187 return (
13288 < >
89+ < h2 > Garbage created change</ h2 >
90+ { /* [% Delta] Gerbage created */ }
91+ < svg ref = { n => garbageCreatedChangeSvg = n ! }
92+ width = { garbageCreatedChangeGraphWidth }
93+ height = { garbageCreatedChangeGraphHeight } >
94+ </ svg >
13395 < h2 > Garbage created</ h2 >
134- < svg ref = { n => node = n } width = { GRAPH_WIDTH } height = { GRAPH_HEIGHT } > </ svg >
96+ { /* [Absolute] Garbage created comparison */ }
97+ < svg ref = { n => garbageCreatedComparisonSvg = n ! }
98+ width = { garbageCreatedComparisonGraphWidth }
99+ height = { garbageCreatedComparisonGraphHeight } >
100+ </ svg >
135101 </ >
136102 ) ;
137103 }
0 commit comments