Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
require_from_group
(version: 0)
Performance testing for jquery-validate's require_from_group method
Comparing performance of:
built-in require_from_group vs modified require_from_group
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<form id="theform"> <input type="checkbox" name="a"/> <input type="checkbox" name="b"/> <input type="checkbox" name="c"/> <input type="checkbox" name="d"/> <input type="checkbox" name="e"/> <input type="checkbox" name="f"/> <input type="checkbox" name="g"/> <input type="checkbox" name="h"/> <input type="checkbox" name="i"/> <input type="checkbox" name="j"/> <input type="checkbox" name="k"/> <input type="checkbox" name="l"/> <input type="checkbox" name="m"/> <input type="checkbox" name="n"/> <input type="checkbox" name="o"/> <input type="checkbox" name="p"/> <input type="checkbox" name="q"/> <input type="checkbox" name="r"/> <input type="checkbox" name="s"/> <input type="checkbox" name="t"/> <input type="checkbox" name="u"/> <input type="checkbox" name="v"/> <input type="checkbox" name="w"/> <input type="checkbox" name="x"/> <input type="checkbox" name="y"/> <input type="checkbox" name="z"/> </form> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"></script>
Script Preparation code:
var validator = $('#theform').validate({ groups: { checkgroup: 'a b c d e f g h i j k l m n o p q r s t u v w x y z', }, }); $.validator.addMethod( "require_from_group_builtin", function( value, element, options ) { var $fields = $( options[ 1 ], element.form ), $fieldsFirst = $fields.eq( 0 ), validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ), isValid = $fields.filter( function() { return validator.elementValue( this ); } ).length >= options[ 0 ]; // Store the cloned validator for future validation $fieldsFirst.data( "valid_req_grp", validator ); // If element isn't being validated, run each require_from_group field's validation rules if ( !$( element ).data( "being_validated" ) ) { $fields.data( "being_validated", true ); $fields.each( function() { validator.element(this); } ); $fields.data('clientside_validation_validated', false) $fields.data( "being_validated", false ); } return isValid; }, $.validator.format( "Please fill at least {0} of these fields." ) ); $.validator.addMethod( "require_from_group_modified", function( value, element, options ) { var $fields = $( options[ 1 ], element.form ), $fieldsFirst = $fields.eq( 0 ), validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ), isValid = $fields.filter( function() { return validator.elementValue( this ); } ).length >= options[ 0 ]; // Store the cloned validator for future validation $fieldsFirst.data( "valid_req_grp", validator ); // If element isn't being validated, run each require_from_group field's validation rules if ( !$( element ).data( "being_validated" ) ) { $fields.data( "being_validated", true ); $fields.each( function() { /* Patch adapted from * https://www.drupal.org/project/clientside_validation/issues/2884667 * https://www.drupal.org/files/issues/clientside_validation-select_or_other_optimization-2884667-4-7.patch */ if ($(this).data('clientside_validation_validated')) { return; } else { $(this).data('clientside_validation_validated', true); validator.element(this); } } ); $fields.data('clientside_validation_validated', false) $fields.data( "being_validated", false ); } return isValid; }, $.validator.format( "Please fill at least {0} of these fields." ) );
Tests:
built-in require_from_group
var selector = 'input[type="checkbox"]'; var $fields = $(selector); $fields.rules('add', { require_from_group_builtin: [1, selector] }); $fields.eq(0).valid();
modified require_from_group
var selector = 'input[type="checkbox"]'; var $fields = $(selector); $fields.rules('add', { require_from_group_modified: [1, selector] }); $fields.eq(0).valid();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
built-in require_from_group
modified require_from_group
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this specific benchmark. **What is being tested?** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. In this case, we have two test cases: "built-in require_from_group" and "modified require_from_group". These tests measure the performance of two different approaches for implementing the `require_from_group` method in jQuery Validate. **What are the options being compared?** The two options being compared are: 1. **Built-in implementation (`require_from_group_builtin`)**: This approach uses a built-in method implemented by jQuery Validate. 2. **Modified implementation (`require_from_group_modified`)**: This approach implements a custom version of `require_from_group` using a different logic. **Pros and Cons of each approach:** * **Built-in implementation (`require_from_group_builtin`)**: + Pros: - Faster execution, as it leverages the optimized implementation by jQuery Validate. - Less code to write and maintain. + Cons: - May not be customizable or flexible enough for specific use cases. - May have limitations in terms of performance or behavior. * **Modified implementation (`require_from_group_modified`)**: + Pros: - More control over the implementation, allowing for customization or optimization for specific use cases. - Can potentially offer better performance or behavior compared to the built-in implementation. + Cons: - Requires more code and maintenance effort. - May introduce bugs or inconsistencies if not implemented correctly. **What is the test setup?** The test cases create a set of checkboxes using jQuery's `$(selector)` method, add rules to validate each checkbox using the `rules('add')` method, and then execute the validation for the first checkbox. The built-in implementation uses the `require_from_group_builtin` method, while the modified implementation uses the `require_from_group_modified` method. **Why is this benchmark important?** This benchmark is likely intended to evaluate the performance and efficiency of the two approaches in different scenarios. By comparing the execution times of these two implementations, developers can make informed decisions about which approach to use depending on their specific requirements and constraints.
Related benchmarks:
jQuery - $(selector, context) VS $(context).find(selector)
require_from_group2
Vanilla js vs jquery: value
jQuery $(selector, context) VS $(context).find(selector) VS Vanilla querySelector
Comments
Confirm delete:
Do you really want to delete benchmark?