JavaScript中JSON.parse()的复杂性是什么? [英] What is the complexity of JSON.parse() in JavaScript?

查看:130
本文介绍了JavaScript中JSON.parse()的复杂性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.我将解析一个非常大的JSON字符串,并且很好奇此内置方法的复杂性.

The title says it all. I'm going to be parsing a very large JSON string and was curious what the complexity of this built in method was.

我希望它是θ(n),其中n是字符串中的字符数,因为它可以确定是否存在语法错误.

I would hope that it's θ(n) where n is the number of characters in the string since it can determine whether there is a syntax error or not.

我尝试搜索,但什么也没想出来.

I tried searching but couldn't come up with anything.

推荐答案

JSON是非常简单的语法,甚至不需要先行.一旦不涉及GC,则纯粹是O(n).

JSON is very simple grammar that does not require even lookaheads. As soon as GC is not involved then it is purely O(n).

这篇关于JavaScript中JSON.parse()的复杂性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆