Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
UTF-8 byte length Arabic 4-mthods
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Browser:
Chrome 109
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
with a loop Arabic
381117.2 Ops/sec
with a regex Arabic
17112.5 Ops/sec
with a TextEncoder ِِArabic
148418.9 Ops/sec
with a Blob Arabic
7661.3 Ops/sec
Script Preparation code:
var arabic_str = "kksldfnjeoliwkfmirewogbregiojrmfikrefnهنصتةبهنمخصةبهخصثةبثصهنخقلةثقملىثقمةلكمسقنلمنكقةلمنيبةىلميبنكلكمطسيوبصثقنلحخثقتلثقنلوسيكملنسيكملklrmglkedrmg;ler,g;lkerdmglkermg;ler,g;lerkmglkerglk;ermg;lermg;hjfbwefseoifnuiwefصثعىبصثبىهصثىةبخهمصقاىلثخقتلةحخثقلةثقلةثقلةثقلةثخقلةحخثقلةخقثلةثحخقلةثينقىلنمقثيىلنمقىلمنيثقسىلقىلمقىلنمكقىلمنقىلمنيثقىلمنقىلمنقثىيةلمنخىثيقمنلةيمنلتىنثتقيىلخهمثقيةلخمثقيىلثقفيىلنثقيةلمنخىفقثيلىىىتنعصثىبمخنثةصبحةثصقخمبىثقخمنهلىةثحكقةلكحثقةلمنثقىلمنثقىلكمثةقلكمثقةلمنىثقلمنىثقلمنىثقلنمكثىقلنمكثقىلمنثيقىلمطنثقىلمنطثقىةسلبثمكسقيلةثطقكةلونطحكصثقنلخحثقةلحكخمقفةاقفهىاقفاىقفةلحخثقهخابهقعثالخهثقتلخهثقالخهاثقهعلخباثقحهخبةصحخثجؤوخحجصسثؤوحخصثرةىخهمثقيلىرخهمثقلىخهثقمللاخهثمقلتحخثقتلبحخصثتبحخصثستىبخهمثقىلخهمنثقىلحخثقىلحثقىلخهمنثقصىلثقةلحخثقىلمخهنثيقىلمصثويبجحصضثنيحخصثتبهختثصقخهلبةثقهنخلمةثقيرنمهىيؤنتءراىهخثقةرثقمرةثقيمخهنلىخهثقنلىخهمثقهتل" var english_str = "UTF-8 encodes each of the 1,112,064 valid code points in the Unicode code space (1,114,112 code points minus 2,048 surrogate code points) using one to four 8-bit bytes (a group of 8 bits is known as an «octet» in the Unicode Standard). Code points wi" function lengthInUtf8Bytes(str) { // Matches only the 10.. bytes that are non-initial characters in a multi-byte sequence. var m = encodeURIComponent(str).match(/%[89ABab]/g); return str.length + (m ? m.length : 0); } function byteLength(str) { // returns the byte length of an utf8 string var s = str.length; for (var i=str.length-1; i>=0; i--) { var code = str.charCodeAt(i); if (code > 0x7f && code <= 0x7ff) s++; else if (code > 0x7ff && code <= 0xffff) s+=2; } return s; } function byteLengthTextEncoder(str) { return (new TextEncoder().encode(str)).length; } function byteLengthBlob(str) { return new Blob([str]).size; }
Tests:
with a loop Arabic
byteLength(arabic_str);
with a regex Arabic
lengthInUtf8Bytes(arabic_str);
with a TextEncoder ِِArabic
byteLengthTextEncoder(arabic_str)
with a Blob Arabic
byteLengthBlob(arabic_str);