encodeURI() vs encodeURIComponent() (v4)

Revision 4 of this benchmark created 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.