How to use samplesComparison method in Best

Best JavaScript code snippet using best

analyze.ts

Source:analyze.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import json2md from 'json2md';8import { BenchmarkComparison, ResultComparison, BenchmarkMetricNames, BenchmarkStats, ResultComparisonBenchmark, ResultComparisonGroup, ResultComparisonProject } from '@best/types';9interface MarkdownTable {10 table: {11 headers: string[];12 rows: string[][];13 }14}15interface SignificantlyChangedSummary {16 improved: string[][]17 regressed: string[][]18}19type GroupedTables = { [projectName: string]: MarkdownTable[] }20function padding(n: number) {21 return n > 022 ? Array.apply(null, Array((n - 1) * 3))23 .map(() => ' ')24 .join('') + '└─ '25 : '';26}27function generateMarkdownFromGroupedTables(tables: GroupedTables) {28 const flattenedTables = Object.keys(tables).reduce((groups, projectName): json2md.DataObject[] => {29 groups.push({ h2: `*${projectName}*` });30 groups.push(...tables[projectName]);31 return groups;32 }, <json2md.DataObject[]>[])33 return json2md(flattenedTables);34}35function generateRow(36 name: string,37 metrics: {38 baseStats: BenchmarkStats;39 targetStats: BenchmarkStats;40 samplesComparison: 0 | 1 | -1;41 },42 includeEmojiTrend: boolean43): string[] {44 const baseStats = metrics.baseStats;45 const targetStats = metrics.targetStats;46 const samplesComparison = metrics.samplesComparison;47 const percentage = (Math.abs(baseStats.median - targetStats.median) / baseStats.median) * 100;48 const relativeTrend = targetStats.median - baseStats.median;49 const sign = Math.sign(relativeTrend) === 1 ? '+' : '';50 const comparisonEmoji = (samplesComparison === 0 ? '👌' : samplesComparison === 1 ? '👎' : '👍');51 return [52 name,53 `${baseStats.median.toFixed(2)} (± ${baseStats.medianAbsoluteDeviation.toFixed(2)}ms)`,54 `${targetStats.median.toFixed(2)} (± ${targetStats.medianAbsoluteDeviation.toFixed(2)}ms)`,55 sign + relativeTrend.toFixed(1) + 'ms (' + percentage.toFixed(1) + '%)' + (includeEmojiTrend ? ` ${comparisonEmoji}` : '')56 ]57}58function generateRowsFromComparison<RowType>(stats: ResultComparison, handler: (node: ResultComparisonBenchmark, parentName: string) => RowType[], name: string = '', initialRows: RowType[] = []) {59 if (stats.type === "project" || stats.type === "group") {60 return stats.comparisons.reduce((rows, node): RowType[] => {61 if (node.type === "project" || node.type === "group") {62 return generateRowsFromComparison(node, handler, node.name, rows);63 } else if (node.type === "benchmark") {64 rows.push(...handler(node, name));65 }66 return rows;67 }, initialRows);68 } else {69 return initialRows;70 }71}72function significantlyChangedRows(stats: ResultComparison, threshold: number, name: string = '', initialRows: SignificantlyChangedSummary = { improved: [], regressed: [] }) {73 const highThreshold = Math.abs(threshold); // handle whether the threshold is positive or negative74 const lowThreshold = -1 * highThreshold;75 if (stats.type === "project" || stats.type === "group") {76 return stats.comparisons.reduce((rows, node): SignificantlyChangedSummary => {77 if (node.type === "project" || node.type === "group") {78 return significantlyChangedRows(node, threshold, node.name, rows);79 } else if (node.type === "benchmark") {80 // for the significantly changed summary, we only check for aggregate81 const metrics = node.metrics.aggregate;82 if (metrics) {83 const { baseStats, targetStats, samplesComparison } = metrics;84 85 if (samplesComparison !== 0 && baseStats.median > 1 && targetStats.median > 1) { // ensures passes Mann-Whiteney U test and results are more than 1ms86 const percentage = (Math.abs(baseStats.median - targetStats.median) / baseStats.median) * 100;87 const relativeTrend = targetStats.median - baseStats.median;88 const relativePercentage = Math.sign(relativeTrend) * percentage;89 const row = generateRow(`${name}/${node.name}`, metrics, false);90 if (relativePercentage < lowThreshold) { // less than a negative is GOOD (things got faster)91 rows.improved.push(row);92 } else if (relativePercentage > highThreshold) { // more than a positive is WORSE (things got slower)93 rows.regressed.push(row);94 }95 }96 }97 }98 return rows;99 }, initialRows)100 } else {101 return initialRows;102 }103}104function generateAllRows(stats: ResultComparison) {105 return generateRowsFromComparison(stats, (node, parentName) => {106 const rows: string[][] = [];107 const emptyFields = Array.apply(null, Array(3)).map(() => '-');108 rows.push([`${parentName}/${node.name}`, ...emptyFields]);109 Object.keys(node.metrics).forEach(metric => {110 const metrics = node.metrics[metric as BenchmarkMetricNames];111 if (metrics) {112 rows.push(generateRow(padding(1) + metric, metrics, true));113 }114 })115 return rows;116 })117}118function generateCommentWithTables(result: BenchmarkComparison, handler: (node: ResultComparisonProject | ResultComparisonGroup, baseCommit: string, targetCommit: string) => MarkdownTable[]) {119 const { baseCommit, targetCommit, comparisons } = result;120 const grouped: GroupedTables = comparisons.reduce((tables, node): GroupedTables => {121 if (node.type === "project" || node.type === "group") {122 const markdownTables = handler(node, baseCommit, targetCommit);123 if (markdownTables.length) {124 return {125 ...tables,126 [node.name]: markdownTables127 }128 }129 return tables;130 }131 return tables;132 }, <GroupedTables>{});133 return generateMarkdownFromGroupedTables(grouped);134}135export function generateComparisonSummary(result: BenchmarkComparison, threshold: number) {136 return generateCommentWithTables(result, (node, base, target) => {137 const changes = significantlyChangedRows(node, threshold);138 const tables: MarkdownTable[] = [];139 140 if (changes.improved.length) {141 tables.push({142 table: {143 headers: [`✅ Improvements`, `base (\`${base}\`)`, `target (\`${target}\`)`, 'trend'],144 rows: changes.improved145 }146 })147 }148 if (changes.regressed.length) {149 tables.push({150 table: {151 headers: [`❌ Regressions`, `base (\`${base}\`)`, `target (\`${target}\`)`, 'trend'],152 rows: changes.regressed153 }154 });155 }156 return tables;157 })158}159function generateAllRowsTable(baseCommit: string, targetCommit: string, stats: ResultComparison): MarkdownTable {160 const { name: benchmarkName } = stats;161 const mdName = benchmarkName.replace('.benchmark', '');162 return {163 table: {164 headers: [`${mdName}`, `base (\`${baseCommit}\`)`, `target (\`${targetCommit}\`)`, 'trend'],165 rows: generateAllRows(stats)166 }167 }168}169export function generateComparisonComment(result: BenchmarkComparison) {170 const tablesMarkdown = generateCommentWithTables(result, (node, base, target) => {171 const tables = node.comparisons.map(child => {172 return generateAllRowsTable(base, target, child);173 })174 return tables;175 });176 return `# Full Results\n\n${tablesMarkdown}`;177}178// this takes all the results and recursively goes through them179// then it creates a flat list of all of the percentages of change180export function generatePercentages(stats: ResultComparison): number[] {181 return generateRowsFromComparison(stats, (node, parentName) => {182 const rows: number[] = [];183 Object.keys(node.metrics).map(metricName => {184 const metrics = node.metrics[metricName as BenchmarkMetricNames];185 if (metrics) {186 const { baseStats, targetStats, samplesComparison } = metrics;187 const baseMed = baseStats.median;188 const targetMed = targetStats.median;189 190 const percentage = Math.abs((baseMed - targetMed) / baseMed * 100);191 const relativeTrend = targetMed - baseMed;192 // ensures passes Mann-Whiteney U test and results are more than 1ms193 if (samplesComparison !== 0 && baseMed > 1 && targetMed > 1) {194 rows.push(Math.sign(relativeTrend) * percentage);195 } else {196 rows.push(0); // otherwise we count it as zero197 }198 }199 })200 return rows;201 })...

Full Screen

Full Screen

comparison1.ts

Source:comparison1.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import { BenchmarkComparison } from '@best/types';8const comparison: BenchmarkComparison = {9 "baseCommit": "abcdef0",10 "targetCommit": "1234567",11 "comparisons": [12 {13 "type": "project",14 "name": "project-foo",15 "comparisons": [16 {17 "type": "group",18 "name": "bar.benchmark",19 "comparisons": [20 {21 "type": "group",22 "name": "bar 1",23 "comparisons": [24 {25 "type": "benchmark",26 "name": "fibonacci 15",27 "metrics": {28 "script": {29 "baseStats": {30 "samples": [31 0.195,32 0.135,33 0.14,34 0.345,35 0.13536 ],37 "sampleSize": 5,38 "samplesQuantileThreshold": 0.8,39 "mean": 0.19,40 "median": 0.14,41 "variance": 0.007,42 "medianAbsoluteDeviation": 0.00543 },44 "targetStats": {45 "samples": [46 0.225,47 0.125,48 0.17,49 0.23,50 0.14551 ],52 "sampleSize": 5,53 "samplesQuantileThreshold": 0.8,54 "mean": 0.179,55 "median": 0.17,56 "variance": 0.002,57 "medianAbsoluteDeviation": 0.04558 },59 "samplesComparison": 060 },61 "aggregate": {62 "baseStats": {63 "samples": [64 1.27,65 0.28,66 0.305,67 0.775,68 0.5669 ],70 "sampleSize": 5,71 "samplesQuantileThreshold": 0.8,72 "mean": 0.638,73 "median": 0.56,74 "variance": 0.133,75 "medianAbsoluteDeviation": 0.25576 },77 "targetStats": {78 "samples": [79 1.505,80 0.575,81 0.78,82 0.475,83 0.73584 ],85 "sampleSize": 5,86 "samplesQuantileThreshold": 0.8,87 "mean": 0.814,88 "median": 0.735,89 "variance": 0.131384,90 "medianAbsoluteDeviation": 0.16091 },92 "samplesComparison": 093 }94 }95 },96 {97 "type": "benchmark",98 "name": "fibonacci 38",99 "metrics": {100 "script": {101 "baseStats": {102 "samples": [103 498.465,104 475.37,105 473.74,106 478.11,107 471.91108 ],109 "sampleSize": 5,110 "samplesQuantileThreshold": 0.8,111 "mean": 479.519,112 "median": 475.37,113 "variance": 93.889,114 "medianAbsoluteDeviation": 2.740115 },116 "targetStats": {117 "samples": [118 478.37,119 476.67,120 471.725,121 482.67,122 479.44123 ],124 "sampleSize": 5,125 "samplesQuantileThreshold": 0.8,126 "mean": 477.775,127 "median": 478.37,128 "variance": 12.982,129 "medianAbsoluteDeviation": 1.7130 },131 "samplesComparison": 0132 },133 "aggregate": {134 "baseStats": {135 "samples": [136 498.735,137 475.635,138 473.955,139 478.305,140 472.14141 ],142 "sampleSize": 5,143 "samplesQuantileThreshold": 0.8,144 "mean": 479.754,145 "median": 475.635,146 "variance": 94.189,147 "medianAbsoluteDeviation": 2.670148 },149 "targetStats": {150 "samples": [151 478.61,152 477.005,153 471.93,154 482.89,155 479.71156 ],157 "sampleSize": 5,158 "samplesQuantileThreshold": 0.8,159 "mean": 478.029,160 "median": 478.61,161 "variance": 13.008,162 "medianAbsoluteDeviation": 1.605163 },164 "samplesComparison": 0165 }166 }167 }168 ]169 }170 ]171 },172 {173 "type": "group",174 "name": "baz.benchmark",175 "comparisons": [176 {177 "type": "group",178 "name": "baz 1",179 "comparisons": [180 {181 "type": "benchmark",182 "name": "fibonacci",183 "metrics": {184 "script": {185 "baseStats": {186 "samples": [187 0.215,188 0.25,189 0.355,190 0.325,191 0.355192 ],193 "sampleSize": 5,194 "samplesQuantileThreshold": 0.8,195 "mean": 0.3,196 "median": 0.325,197 "variance": 0.003,198 "medianAbsoluteDeviation": 0.03199 },200 "targetStats": {201 "samples": [202 0.185,203 0.2,204 0.16,205 0.19,206 0.375207 ],208 "sampleSize": 5,209 "samplesQuantileThreshold": 0.8,210 "mean": 0.222,211 "median": 0.19,212 "variance": 0.006,213 "medianAbsoluteDeviation": 0.01214 },215 "samplesComparison": 0216 },217 "aggregate": {218 "baseStats": {219 "samples": [220 1.29,221 1.02,222 0.735,223 0.585,224 0.615225 ],226 "sampleSize": 5,227 "samplesQuantileThreshold": 0.8,228 "mean": 0.849,229 "median": 0.735,230 "variance": 0.072,231 "medianAbsoluteDeviation": 0.15232 },233 "targetStats": {234 "samples": [235 1.22,236 0.885,237 0.335,238 0.675,239 0.705240 ],241 "sampleSize": 5,242 "samplesQuantileThreshold": 0.8,243 "mean": 0.764,244 "median": 0.705,245 "variance": 0.084,246 "medianAbsoluteDeviation": 0.180247 },248 "samplesComparison": 0249 }250 }251 }252 ]253 }254 ]255 }256 ]257 }258 ]259}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPractice = require('./bestPractice.js');2var bp = new BestPractice();3var sample1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];4var sample2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];5var result = bp.samplesComparison(sample1, sample2);6console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestMatch = require('./BestMatch');2var fs = require('fs');3var samples = fs.readFileSync('samples.txt').toString().split("4");5var test = fs.readFileSync('test.txt').toString().split("6");7var bestMatch = new BestMatch();8var result = bestMatch.samplesComparison(samples, test);9console.log(result);10var BestMatch = function(){};11BestMatch.prototype.samplesComparison = function(samples, test){12 var result = [];13 var sample = [];14 var sampleName = "";15 var sampleData = "";16 var sampleLength = 0;17 var testLength = test.length;18 var i = 0;19 var j = 0;20 var k = 0;21 var l = 0;22 var count = 0;23 var percent = 0;24 var temp = 0;25 var tempName = "";26 var tempData = "";27 var tempLength = 0;28 for(i=0; i<samples.length; i++){29 if(samples[i] == ""){30 continue;31 }32 sample = samples[i].split(" ");33 sampleName = sample[0];34 sampleData = sample[1];35 sampleLength = sampleData.length;36 count = 0;37 percent = 0;38 for(j=0; j<testLength; j++){39 if(test[j] == ""){40 continue;41 }42 for(k=0; k<sampleLength; k++){43 if(test[j] == sampleData[k]){44 count++;45 }46 }47 }48 percent = (count/sampleLength)*100;49 result.push({"name":sampleName, "percent":percent});50 }51 for(l=0; l<result.length; l++){52 for(m=l+1; m<result.length; m++){53 if(result[l].percent < result[m].percent){54 temp = result[l].percent;55 tempName = result[l].name;56 result[l].percent = result[m].percent;57 result[l].name = result[m].name;58 result[m].percent = temp;59 result[m].name = tempName;60 }61 }62 }63 return result;

Full Screen

Using AI Code Generation

copy

Full Screen

1var samplesComparison = require('./BestMatch.js').samplesComparison;2var sample1 = [1, 2, 3, 4, 5];3var sample2 = [1, 3, 5, 7, 9, 11];4var sample3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];5var sample4 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];6var bestMatch = new samplesComparison(sample1, sample2, sample3, sample4);7var result = bestMatch.getBestMatch();8console.log(result);9var samplesComparison = require('./BestMatch.js').samplesComparison;10var sample1 = [1, 2, 3, 4, 5];11var sample2 = [1, 3, 5, 7, 9, 11];12var sample3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];13var sample4 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];14var bestMatch = new samplesComparison(sample1, sample2, sample3, sample4);15var result = bestMatch.getBestMatch();16console.log(result);17var samplesComparison = require('./BestMatch.js').samplesComparison;18var sample1 = [1, 2, 3, 4, 5];19var sample2 = [1, 3, 5, 7, 9, 11];20var sample3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(BestMatch.samplesComparison("string1", "string2"));2console.log(BestMatch.samplesComparison("string1", "string2"));3console.log(BestMatch.samplesComparison("string1", "string2"));4console.log(BestMatch.samplesComparison("string1", "string2"));5console.log(BestMatch.samplesComparison("string1", "string2"));6console.log(BestMatch.samplesComparison("string1", "string2"));7console.log(BestMatch.samplesComparison("string1", "string2"));8console.log(BestMatch.samplesComparison("string1", "string2"));9console.log(BestMatch.samplesComparison("string1", "string2"));10console.log(BestMatch.samplesComparison("string1", "string2"));11console.log(BestMatch.samplesComparison("string1", "string2"));12console.log(BestMatch.samplesComparison("string1", "string2"));

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestMatch = require("./bestMatch");2var bestMatch = new BestMatch();3var sampleTexts = ["The quick brown fox jumps over the lazy dog", "The quick brown fox jumped over the lazy dog", "The quick brown fox jumps over the lazy dog."];4var targetTexts = ["The quick brown fox jumps over the lazy dog", "The quick brown fox jumped over the lazy dog", "The quick brown fox jumps over the lazy dog."];5var result = bestMatch.samplesComparison(sampleTexts, targetTexts);6console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1import BestMatch from './BestMatch.js';2let bm = new BestMatch();3let sample1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];4let sample2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];5let match = bm.samplesComparison(sample1, sample2);6console.log(`The match percentage is: ${match}`);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestMatch = require('./bestMatch');2var fs = require('fs');3var bm = new BestMatch();4var sampleImage = fs.readFileSync('sample.jpg');5bm.samplesComparison(sampleImage, function(err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});12var BestMatch = require('./bestMatch');13var fs = require('fs');14var bm = new BestMatch();15var sampleImage = fs.readFileSync('sample.jpg');16bm.samplesComparison(sampleImage, function(err, result) {17 if (err) {18 console.log(err);19 } else {20 console.log(result);21 }22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPath = require('best-path');2var path1 = {3 {4 },5 {6 },7 {8 }9};10var path2 = {11 {12 },13 {14 },15 {16 }17};18var bestPath = new BestPath();19var bestPaths = bestPath.samplesComparison([path1, path2]);20console.log(bestPaths);21[ { name: 'path1', sample: [ [Object], [Object], [Object] ] },22 { name: 'path2', sample: [ [Object], [Object], [Object] ] } ]

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful