Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
validateCsvEntry
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser:
Chrome 138
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
validateCsvEntry
68.5 Ops/sec
validateCsvEntry Optimized
76.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here--> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script> <script src="https://unpkg.com/fastest-validator@1.19.1/index.js"></script>
Script Preparation code:
function hasValue(value) { if ( (value === null) || (value === undefined) ) return false; return true; } function isUuid(uuid) { if ( !hasValue(uuid) ) return false; // eslint-disable-next-line var regex = /^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/i; return regex.test(uuid); } function getSchemaFieldMetadata() { return JSON.parse(`{"actionTaken":{"name":"actionTaken","type":"Enum8('DENY' = 0, 'ALLOW' = 1, 'OPEN' = 2, 'CLOSE' = 3, 'UPDATE' = 4)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"DENY":0,"ALLOW":1,"OPEN":2,"CLOSE":3,"UPDATE":4}},"ruleId":{"name":"ruleId","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"sessionId":{"name":"sessionId","type":"UInt32","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"segmentLogicalId":{"name":"segmentLogicalId","type":"UUID","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"inputInterface":{"name":"inputInterface","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"protocol":{"name":"protocol","type":"UInt16","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"sourceIp":{"name":"sourceIp","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"destIp":{"name":"destIp","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"sourcePort":{"name":"sourcePort","type":"UInt16","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"destPort":{"name":"destPort","type":"UInt16","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"destination":{"name":"destination","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"domainName":{"name":"domainName","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"firewallPolicyName":{"name":"firewallPolicyName","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"segmentName":{"name":"segmentName","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"extensionHeader":{"name":"extensionHeader","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"application":{"name":"application","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"sessionDurationSecs":{"name":"sessionDurationSecs","type":"UInt32","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"bytesSent":{"name":"bytesSent","type":"UInt32","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"bytesReceived":{"name":"bytesReceived","type":"UInt32","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"closeReason":{"name":"closeReason","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"signatureId":{"name":"signatureId","type":"UInt32","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"signatureName":{"name":"signatureName","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"signatureCategory":{"name":"signatureCategory","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"signatureSeverity":{"name":"signatureSeverity","type":"UInt32","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"threatImpact":{"name":"threatImpact","type":"Enum8('SUSPICIOUS' = 0, 'LOW' = 1, 'MEDIUM' = 2, 'HIGH' = 3, 'CRITICAL' = 4)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"SUSPICIOUS":0,"LOW":1,"MEDIUM":2,"HIGH":3,"CRITICAL":4}},"threatSourceIp":{"name":"threatSourceIp","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"threatSourceGeoCountry":{"name":"threatSourceGeoCountry","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"threatTargetIp":{"name":"threatTargetIp","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"enterpriseLogicalId":{"name":"enterpriseLogicalId","type":"UUID","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"edgeLogicalId":{"name":"edgeLogicalId","type":"UUID","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"edgeName":{"name":"edgeName","type":"String","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"timestamp":{"name":"timestamp","type":"DateTime","default_type":"DEFAULT","default_expression":"now()","comment":"","codec_expression":"","ttl_expression":""},"idpsAlertType":{"name":"idpsAlertType","type":"Enum8('IDS' = 0, 'IPS' = 1)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"IDS":0,"IPS":1}},"idpsAction":{"name":"idpsAction","type":"Enum8('ALLOW' = 0, 'MONITOR' = 1, 'DENY' = 2)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"ALLOW":0,"MONITOR":1,"DENY":2}},"urlCategories":{"name":"urlCategories","type":"Array(UInt16)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"urlCatFilterAction":{"name":"urlCatFilterAction","type":"Enum8('ALLOW' = 0, 'MONITOR' = 1, 'DENY' = 2)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"ALLOW":0,"MONITOR":1,"DENY":2}},"urlRisk":{"name":"urlRisk","type":"Enum8('UNKNOWN' = 0, 'HIGH' = 1, 'SUSPICIOUS' = 2, 'MEDIUM' = 3, 'LOW' = 4, 'TRUSTWORTHY' = 5)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"UNKNOWN":0,"HIGH":1,"SUSPICIOUS":2,"MEDIUM":3,"LOW":4,"TRUSTWORTHY":5}},"urlReputationAction":{"name":"urlReputationAction","type":"Enum8('ALLOW' = 0, 'MONITOR' = 1, 'DENY' = 2)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"ALLOW":0,"MONITOR":1,"DENY":2}},"maliciousIpCategories":{"name":"maliciousIpCategories","type":"Array(UInt16)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""},"malIpAction":{"name":"malIpAction","type":"Enum8('ALLOW' = 0, 'MONITOR' = 1, 'DENY' = 2)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":"","enums":{"ALLOW":0,"MONITOR":1,"DENY":2}},"engineType":{"name":"engineType","type":"Array(UInt32)","default_type":"","default_expression":"","comment":"","codec_expression":"","ttl_expression":""}}`); } const isValidUInt = (value) => _.toNumber(value) >= 0 && _.isInteger(_.toNumber(value)); const isValidInt = (value) => _.isInteger(_.toNumber(value)); const isValidFloat = (value) => _.isFinite(_.toNumber(value)); const isValidUuid = (value) => value === '' || isUuid(value); const isValidDate = (value) => value === '' || (!isValidFloat(value || NaN) && !isNaN(new Date(value))); const isValidEnum = (value, statsType, csvField) => value === '' || _.has(getSchemaFieldMetadata(statsType)[csvField].enums, value); const validDataTypeMap = { 'UInt8': isValidUInt, 'UInt16': isValidUInt, 'UInt32': isValidUInt, 'UInt64': isValidUInt, 'UInt128': isValidUInt, 'UInt256': isValidUInt, 'Int8': isValidInt, 'Int16': isValidInt, 'Int32': isValidInt, 'Int64': isValidInt, 'Int128': isValidInt, 'Int256': isValidInt, 'Float32': isValidFloat, 'Float64': isValidFloat, 'UUID': isValidUuid, 'DateTime': isValidDate, 'Enum': isValidEnum, }; Object.freeze(validDataTypeMap); function isValidDataType(statsType, csvField, dataType, value) { const validDataTypeFn = validDataTypeMap[dataType.startsWith('Enum') ? 'Enum' : dataType]; if (!_.isNil(validDataTypeFn)) { return validDataTypeFn(value, statsType, csvField); } return true; } function getCsvEntry() { return JSON.parse('{"columns":["","\\"9ifvMYhsOtWSUIGV7De6k5\\"","9077","69e45410-4264-44e0-ba94-5eac5251b764","\\"VCF\\"","1","\\"241.152.20.27\\"","\\"232.214.227.14\\"","20609","12831","\\"https://hlbnwz4o6ACBcjeksM72Za.com\\"","\\"hlbnwz4o6ACBcjeksM72Za.com\\"","\\"ALLOW_1989\\"","\\"Global\\"","","\\"Outlook\\"","192","86355","91792","\\"\\"","","","","","","","\\"\\"","","4b534ae2-8f67-4ec8-85a9-768cd4354fcb","402dffed-2151-4e27-9472-1923ac147b1c","","2025-07-21 20:27:10","","","","","","","","MONITOR","",""],"header":["actionTaken","ruleId","sessionId","segmentLogicalId","inputInterface","protocol","sourceIp","destIp","sourcePort","destPort","destination","domainName","firewallPolicyName","segmentName","extensionHeader","application","sessionDurationSecs","bytesSent","bytesReceived","closeReason","signatureId","signatureName","signatureCategory","signatureSeverity","threatImpact","threatSourceIp","threatSourceGeoCountry","threatTargetIp","enterpriseLogicalId","edgeLogicalId","edgeName","timestamp","idpsAlertType","idpsAction","urlCategories","urlCatFilterAction","urlRisk","urlReputationAction","maliciousIpCategories","malIpAction","engineType",""]}'); } const csvEntry = getCsvEntry(); function validateCsvEntry({ columns, header}, statsType) { // Theoretically this should never happen since we are relying on the schema object to initialize correctly. // If this error occurs, we are generating the schema for some unwanted column type if (columns.length !== header.length) { return { entry: columns.join(','), malformed: true, failedFields: [...header], header: header.join(',') }; } let i = 0; const fieldInfo = getSchemaFieldMetadata(statsType); const failedFields = []; for (const csvField in fieldInfo) { if (!isValidDataType(statsType, csvField, fieldInfo[csvField].type, columns[i])) { failedFields.push(csvField); } ++i; } return { entry: columns.join(','), malformed: false, failedFields: failedFields, header: header.join(',') }; }
Tests:
validateCsvEntry
/*When writing async/deferred tests, use `deferred.resolve()` to mark test as done*/ for (let i = 0; i < 1000; i++) { validateCsvEntry(csvEntry, 'FIREWALLLOGS_PROTO'); }
validateCsvEntry Optimized
const v = new FastestValidator(); const schema = { id: { type: "number", positive: true, integer: true }, name: { type: "string", min: 3, max: 255 }, status: "boolean" // short-hand def }; const check = v.compile(schema); console.log(check({ id: 5, name: "John", status: true }));