简体   繁体   English

Javascript大数组性能

[英]Javascript large array performance

I am generating randomized string sequences from a 4 different arrays containing up to 700 strings each and now I'm worrying about the performance. 我正在从4个不同的数组生成随机的字符串序列,每个数组包含多达700个字符串,现在我担心性能。

Are there any easy ways to improve perfomance of a static site like this, where you have single jquery click listener and it's randomly creating sentences based on the strings 是否有任何简单的方法可以改善这样的静态网站的性能,在这种情况下,您只有一个jquery click侦听器,并且它根据字符串随机创建句子

    var first = [700_ITEMS]
    var sec = [400_ITEMS]
    $(document).ready(function() {
        $('#generate button').click(function(){
            $('#slide1 h1').html(first[Math.floor(Math.random() * first.length)]+" "+sec[Math.floor(Math.random() * sec.length)]);
        })
    });

Maybe I can read the strings somehow on the fly? 也许我可以即时读取字符串?

Lookup is done once using the index, there's no performance issue unless you are doing something else to populate arrays. 使用索引一次即可完成查找,除非您要执行其他操作来填充数组,否则不会出现性能问题。

The only possible improvement would be to prerender content but it kind of defeats the purpose of the algorithm. 唯一可能的改进是预渲染内容,但这有点违反了算法的目的。

There isn't much of a performance issue here, at all. 这里根本没有性能问题。 You're not calculating all possible permutations between both arrays. 您并没有计算两个数组之间所有可能的排列。 It's a simple lookup to find the values, once both random numbers have been found. 一旦找到两个随机数,就可以轻松查找这些值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM