encodeURI() vs encodeURIComponent() (v3)

Revision 3 of this benchmark created by matt on


Description

encodeURI() vs encodeURIComponent()

Setup

var special_encode = function(s){
                // Use an HTML track to safely encode a string using the char codes
                
                if(!s){
                        return s;
                }
                var i, result = [];
                for(i = 0; i < s.length; i++){
                        if(s.charCodeAt(i) < 128){
                                result.push(s.charAt(i));
                        }else{
                                result.push(encodeURIComponent(s.charAt(i)));
                        }
                }
                return encodeURIComponent(result.join(''));
        };

Test runner

Ready to run.

Testing in
TestOps/sec
encodeURI()
encodeURI('контакты')
ready
encodeURIComponent()
encodeURIComponent('контакты')
ready
special encode
special_encode('контакты')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.