Best Phoronix-test-suite code snippet using pts_test_result.normalize_buffer_values
pts_result_file_analyzer.php
Source:pts_result_file_analyzer.php
...548 $geo_mean = pts_result_file_analyzer::generate_geometric_mean_result($result_file, true, $contained_tests);549 if($geo_mean)550 {551 $geo_mean->test_profile->set_test_title('Geometric Mean Of ' . $suite->get_title() . (stripos($suite->get_title(), 'Test') === false ? ' Tests' : null));552 $geo_mean->normalize_buffer_values();553 $geo_mean->set_annotation('Geometric mean based upon tests: ' . pts_arrays::implode_list($contained_tests));554 $geo_mean_results[] = $geo_mean;555 }556 }557 return $geo_mean_results;558 }559 public static function generate_geometric_mean_result($result_file, $do_sort = false, $limit_to = false, $best_is_last = false)560 {561 $results = array();562 $system_count = $result_file->get_system_count();563 foreach($result_file->get_result_objects() as $result)564 {565 if($result->test_profile->get_identifier() == null || $result->test_profile->get_display_format() != 'BAR_GRAPH' || $system_count > $result->test_result_buffer->get_count())566 {567 // Skip data where it's not a proper test, not a singular data value, or not all systems ran within the result file568 continue;569 }570 if($limit_to)571 {572 if(is_array($limit_to))573 {574 if(!in_array($result->test_profile->get_identifier(), $limit_to) && !in_array($result->test_profile->get_identifier(false), $limit_to))575 {576 continue;577 }578 }579 else580 {581 if($limit_to != $result->test_profile->get_identifier())582 {583 continue;584 }585 }586 }587 foreach($result->test_result_buffer->get_buffer_items() as $buffer_item)588 {589 $r = $buffer_item->get_result_value();590 if(!is_numeric($r) || $r == 0)591 {592 continue;593 }594 if($result->test_profile->get_result_proportion() == 'LIB')595 {596 // convert to HIB597 $r = (1 / $r) * 100;598 }599 $ri = $buffer_item->get_result_identifier();600 if(!isset($results[$ri]))601 {602 $results[$ri] = array();603 }604 $results[$ri][] = $r;605 }606 }607 foreach($results as $identifier => $values)608 {609 if(count($values) < 2)610 {611 // If small result file with not a lot of data, don't bother showing...612 unset($results[$identifier]);613 }614 }615 if(!empty($results))616 {617 $test_profile = new pts_test_profile();618 $test_result = new pts_test_result($test_profile);619 $test_result->test_profile->set_test_title('Geometric Mean Of ' . ($limit_to && !is_array($limit_to) ? $limit_to : 'All Test Results'));620 $test_result->test_profile->set_identifier(null);621 $test_result->test_profile->set_version(null);622 $test_result->test_profile->set_result_proportion(null);623 $test_result->test_profile->set_display_format('BAR_GRAPH');624 $test_result->test_profile->set_result_scale('Geometric Mean');625 $test_result->test_profile->set_result_proportion('HIB');626 $test_result->set_used_arguments_description('Result Composite');627 $test_result->set_used_arguments('Geometric-Mean');628 $test_result->test_result_buffer = new pts_test_result_buffer();629 foreach($results as $identifier => $values)630 {631 if(count($values) < 2)632 {633 return false;634 }635 $values = pts_math::geometric_mean($values);636 $test_result->test_result_buffer->add_test_result($identifier, pts_math::set_precision($values, 3));637 }638 if(!$result_file->is_multi_way_comparison() && $do_sort)639 {640 $test_result->sort_results_by_performance();641 if($best_is_last)642 {643 $test_result->test_result_buffer->buffer_values_reverse();644 }645 }646 $test_result->dynamically_generated = true;647 return $test_result;648 }649 return false;650 }651 public static function generate_geometric_mean_result_per_test($result_file, $do_sort = false, $selector = null, $best_is_last = false)652 {653 $geo_results = array();654 $results = array();655 $system_count = $result_file->get_system_count();656 foreach($result_file->get_result_objects() as $result)657 {658 if(($selector == null && $result->test_profile->get_identifier() == null) || $result->test_profile->get_display_format() != 'BAR_GRAPH' || $system_count > $result->test_result_buffer->get_count())659 {660 // Skip data where it's not a proper test, not a singular data value, or not all systems ran within the result file661 continue;662 }663 if($selector != null && strpos($result->get_arguments_description(), $selector) === false && strpos($result->test_profile->get_title(), $selector) === false && strpos($result->test_profile->get_result_scale(), $selector) === false)664 {665 continue;666 }667 foreach($result->test_result_buffer->get_buffer_items() as $buffer_item)668 {669 $r = $buffer_item->get_result_value();670 if(!is_numeric($r) || $r == 0)671 {672 continue;673 }674 if($result->test_profile->get_result_proportion() == 'LIB')675 {676 // convert to HIB677 $r = (1 / $r) * 100;678 }679 $ri = $buffer_item->get_result_identifier();680 if(!isset($results[$result->test_profile->get_title()]))681 {682 $results[$result->test_profile->get_title()] = array();683 }684 if(!isset($results[$result->test_profile->get_title()][$ri]))685 {686 $results[$result->test_profile->get_title()][$ri] = array();687 }688 $results[$result->test_profile->get_title()][$ri][] = $r;689 }690 }691 if(count($results) < 2)692 {693 return array();694 }695 foreach($results as $test => $test_results)696 {697 foreach($test_results as $identifier => $values)698 {699 if(false && count($values) < 4)700 {701 // If small result file with not a lot of data, don't bother showing...702 unset($results[$test][$identifier]);703 }704 }705 if(empty($results[$test]))706 {707 unset($results[$test]);708 }709 }710 foreach($results as $test_title => $test_results)711 {712 $test_profile = new pts_test_profile();713 $test_result = new pts_test_result($test_profile);714 $test_result->test_profile->set_test_title($test_title);715 $test_result->test_profile->set_identifier(null);716 $test_result->test_profile->set_version(null);717 $test_result->test_profile->set_result_proportion(null);718 $test_result->test_profile->set_display_format('BAR_GRAPH');719 $test_result->test_profile->set_result_scale('Geometric Mean');720 $test_result->test_profile->set_result_proportion('HIB');721 $test_result->set_used_arguments_description(($selector ? $selector . ' ' : null) . 'Geometric Mean');722 $test_result->set_used_arguments('Geometric-Mean');723 $test_result->test_result_buffer = new pts_test_result_buffer();724 foreach($test_results as $identifier => $values)725 {726 $values = pts_math::geometric_mean($values);727 $precised = pts_math::set_precision($values, 3);728 if($values != 0 && $precised == 0)729 {730 // Don't use precision if it ends up rounding result too small in certain situations731 $precised = $values;732 }733 $test_result->test_result_buffer->add_test_result($identifier, $precised);734 }735 if(!$result_file->is_multi_way_comparison() || $do_sort)736 {737 $test_result->sort_results_by_performance();738 if($best_is_last)739 {740 $test_result->test_result_buffer->buffer_values_reverse();741 }742 }743 $test_result->dynamically_generated = true;744 $geo_results[] = $test_result;745 }746 return $geo_results;747 }748 public static function generate_harmonic_mean_result($result_file, $do_sort = false, $best_is_last = false)749 {750 $results = array();751 $system_count = $result_file->get_system_count();752 foreach($result_file->get_result_objects() as $result)753 {754 if($result->test_profile->get_identifier() == null || $result->test_profile->get_display_format() != 'BAR_GRAPH' || $result->test_profile->get_result_proportion() == 'LIB' || $system_count > $result->test_result_buffer->get_count())755 {756 // Skip data where it's not a proper test, not a singular data value, or not all systems ran within the result file, or lower is better for results757 continue;758 }759 $rs = $result->test_profile->get_result_scale();760 if(strpos($rs, '/') === false && stripos($rs, ' per ') === false && stripos($rs, 'FPS') === false && stripos($rs, 'bps') === false && stripos($rs, 'iops') === false)761 {762 // Harmonic mean is relevant for tests of rates, MB/s, FPS, ns/day, etc.763 continue;764 }765 foreach($result->test_result_buffer->get_buffer_items() as $buffer_item)766 {767 $ri = $buffer_item->get_result_identifier();768 if(!isset($results[$rs][$ri]))769 {770 $results[$rs][$ri] = array();771 }772 $results[$rs][$ri][] = $buffer_item->get_result_value();773 }774 }775 foreach($results as $result_scale => $group)776 {777 foreach($group as $identifier => $values)778 {779 if(count($values) < 4)780 {781 // If small result file with not a lot of data, don't bother showing...782 unset($results[$result_scale][$identifier]);783 }784 }785 }786 if(!empty($results))787 {788 $test_results = array();789 foreach($results as $result_scale => $group)790 {791 $parsed = array();792 foreach($group as $identifier => $values)793 {794 $parsed[$identifier] = pts_math::harmonic_mean($values);795 }796 if(empty($parsed) || count($parsed) < 2)797 {798 continue;799 }800 $test_profile = new pts_test_profile();801 $test_result = new pts_test_result($test_profile);802 $test_result->test_profile->set_test_title('Harmonic Mean Of ' . $result_scale . ' Test Results');803 $test_result->test_profile->set_identifier(null);804 $test_result->test_profile->set_version(null);805 $test_result->test_profile->set_result_proportion(null);806 $test_result->test_profile->set_display_format('BAR_GRAPH');807 $test_result->test_profile->set_result_scale($result_scale);808 $test_result->test_profile->set_result_proportion('HIB');809 $test_result->set_used_arguments_description('Harmonic Mean');810 $test_result->set_used_arguments('Harmonic-Mean - ' . $result_scale);811 $test_result->test_result_buffer = new pts_test_result_buffer();812 foreach($parsed as $identifier => $values)813 {814 $test_result->test_result_buffer->add_test_result($identifier, pts_math::set_precision($values, 3));815 }816 if(!$result_file->is_multi_way_comparison() || $do_sort)817 {818 $test_result->sort_results_by_performance();819 if($best_is_last)820 {821 $test_result->test_result_buffer->buffer_values_reverse();822 }823 }824 $test_result->dynamically_generated = true;825 $test_results[] = $test_result;826 }827 return $test_results;828 }829 return array();830 }831 public static function display_result_file_stats_pythagorean_means($result_file, $highlight_identifier = null)832 {833 $ret = null;834 foreach(pts_result_file_analyzer::generate_harmonic_mean_result($result_file, true, true) as $harmonic_mean_result)835 {836 $ret .= pts_result_file_output::test_result_to_text($harmonic_mean_result, pts_client::terminal_width(), true, $highlight_identifier, true) . PHP_EOL;837 }838 $geometric_mean = pts_result_file_analyzer::generate_geometric_mean_result($result_file, true, false, true);839 if($geometric_mean)840 {841 $ret .= pts_result_file_output::test_result_to_text($geometric_mean, pts_client::terminal_width(), true, $highlight_identifier, true);842 }843 if($ret != null)844 {845 $ret .= PHP_EOL;846 }847 return $ret;848 }849 public static function display_results_wins_losses($result_file, $highlight_result_identifier = null, $prepend_lines = ' ')850 {851 $output = null;852 $result_file_identifiers_count = $result_file->get_system_count();853 $wins = array();854 $losses = array();855 $tests_counted = 0;856 $possible_evaluate_result_count = 0;857 foreach($result_file->get_result_objects() as $result)858 {859 if($result->test_profile->get_identifier() == null)860 {861 continue;862 }863 $possible_evaluate_result_count++;864 if($result->test_result_buffer->get_count() < 2 || $result->test_result_buffer->get_count() < floor($result_file_identifiers_count / 2))865 {866 continue;867 }868 $tests_counted++;869 $winner = $result->get_result_first();870 $loser = $result->get_result_last();871 if(!isset($wins[$winner]))872 {873 $wins[$winner] = 1;874 }875 else876 {877 $wins[$winner]++;878 }879 if(!isset($losses[$loser]))880 {881 $losses[$loser] = 1;882 }883 else884 {885 $losses[$loser]++;886 }887 }888 if(empty($wins) || empty($losses))889 {890 return;891 }892 arsort($wins);893 arsort($losses);894 $table = array();895 $table[] = array(pts_client::cli_colored_text('WINS:', 'green', true), '', '');896 $highlight_row = -1;897 foreach($wins as $identifier => $count)898 {899 $table[] = array($identifier . ': ', $count . ' ', ' [' . pts_math::set_precision($count / $tests_counted * 100, 1) . '%]');900 if($highlight_result_identifier && $highlight_result_identifier == $identifier)901 {902 $highlight_row = count($table) - 1;903 }904 }905 $table[] = array('', '', '');906 $table[] = array(pts_client::cli_colored_text('LOSSES: ', 'red', true), '', '');907 $highlight_row = -1;908 foreach($losses as $identifier => $count)909 {910 $table[] = array($identifier . ': ', $count, ' [' . pts_math::set_precision($count / $tests_counted * 100, 1) . '%]');911 if($highlight_result_identifier && $highlight_result_identifier == $identifier)912 {913 $highlight_row = count($table) - 1;914 }915 }916 $output .= pts_user_io::display_text_table($table, $prepend_lines, 0, 0, false, $highlight_row) . PHP_EOL;917 $output .= $prepend_lines . pts_client::cli_colored_text('TESTS COUNTED: ', 'cyan', true) . ($tests_counted == $possible_evaluate_result_count ? $tests_counted : $tests_counted . ' of ' . $possible_evaluate_result_count) . PHP_EOL;918 return $output;919 }920 public static function display_results_baseline_two_way_compare($result_file, $drop_flat_results = false, $border_table = false, $rich_text = false, $prepend_to_lines = null)921 {922 $table = array(array('Test', 'Configuration', 'Relative'));923 $color_rows = array();924 foreach($result_file->get_result_objects() as $ro)925 {926 if($ro->test_profile->get_display_format() != 'BAR_GRAPH')927 {928 continue;929 }930 $analyze_ro = clone $ro;931 if($drop_flat_results)932 {933 $analyze_ro->remove_unchanged_results(0.3);934 }935 $buffer_identifiers = $analyze_ro->test_result_buffer->get_identifiers();936 if(count($buffer_identifiers) != 2)937 {938 continue;939 }940 $analyze_ro->normalize_buffer_values(pts_arrays::first_element($buffer_identifiers));941 $result = $analyze_ro->test_result_buffer->get_value_from_identifier(pts_arrays::last_element($buffer_identifiers));942 if(empty($result))943 {944 continue;945 }946 $result = round($result, 3);947 if($drop_flat_results && $result == 1)948 {949 continue;950 }951 if($rich_text && ($result < 0.97 || $result > 1.03))952 {953 $color_rows[count($table)] = $result < 1 ? 'red' : 'green';954 }...
normalize_buffer_values
Using AI Code Generation
1require_once('pts-test-result.php');2$test = new pts_test_result();3$test->normalize_buffer_values();4require_once('pts-test-result-parser.php');5$test = new pts_test_result_parser();6$test->normalize_buffer_values();7Fatal error: Call to undefined method pts_test_result::normalize_buffer_values() in /var/www/html/2.php on line 78Fatal error: Call to undefined method pts_test_result_parser::normalize_buffer_values() in /var/www/html/2.php on line 129Your name to display (optional):10Your name to display (optional):
normalize_buffer_values
Using AI Code Generation
1$buffer = array(1,2,3,4,5,6,7,8,9,10);2$buffer = pts_test_result::normalize_buffer_values($buffer);3print_r($buffer);4$buffer = array(1,2,3,4,5,6,7,8,9,10);5$buffer = pts_test_result::normalize_buffer_values($buffer, 10);6print_r($buffer);7$buffer = array(1,2,3,4,5,6,7,8,9,10);8$buffer = pts_test_result::normalize_buffer_values($buffer, 10, 5);9print_r($buffer);
normalize_buffer_values
Using AI Code Generation
1$buffer = array(1,2,3,4,5,6,7,8,9,10);2$buffer = pts_test_result::normalize_buffer_values($buffer);3print_r($buffer);4$buffer = array(1,2,3,4,5,6,7,8,9,10);5$buffer = pts_test_result::normalize_buffer_values($buffer, 10);6print_r($buffer);7$buffer = array(1,2,3,4,5,6,7,8,9,10);8$buffer = pts_test_result::normalize_buffer_values($buffer, 10, 5);9print_r($buffer);
normalize_buffer_values
Using AI Code Generation
1require_once('pts_test_result.php');2$test_result = new pts_test_result('test_result_buffer.txt');3$test_result->normalize_buffer_values(5);4$test_result-tsave_buffer_to_file('normalized_test_result_buffer.txt');5require_once('pts_test_result.php');6$test_result new pts_test_result('test_result_buffer.txt');7$buffer $test_result->get_result_buffer();8foreach($buffer as $key > $value)9{10';11}12require_once('pts_test_result.php');13$test_result new pts_test_result('test_result_buffer.txt');14$buffer_count $test_result->get_result_buffer_count();15echo $buffer_count;16require_once('pts_test_result.php');17$test_result new pts_test_result('test_result_buffer.txt');18$buffer_average $test_result->get_result_buffer_average();19echo $buffer_average;
normalize_buffer_values
Using AI Code Generation
1require_once('pts_test_result.php');2$test_result = new pts_test_result('test_result_buffer.txt');3$test_result->normalize_buffer_values(5);4$test_result->save_buffer_to_file('normalized_test_result_buffer.txt');5require_once('pts_test_result.php');6$test_result = new pts_test_result('test_result_buffer.txt');7$buffer = $test_result->get_result_buffer();8foreach($buffer as $key => $value)9{10';11}12require_once('pts_test_result.php');13$test_result = new pts_test_result('test_result_buffer.txt');14$buffer_count = $test_result->get_result_buffer_count();15echo $buffer_count;16require_once('pts_test_result.php');17$test_result = new pts_test_result('test_result_buffer.txt');18$buffer_average = $test_result->get_result_buffer_average();19echo $buffer_average;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with normalize_buffer_values on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!