Comparing large strings in JavaScript with a hash

前端 未结 3 1591
小蘑菇
小蘑菇 2021-02-05 17:26

I have a form with a textarea that can contain large amounts of content (say, articles for a blog) edited using one of a number of third party rich text editors. I\'m trying to

3条回答
  •  旧时难觅i
    2021-02-05 18:17

    I made a JSperf rev that might be useful here for performance measuring. Please add different revisions and different types of checks to the ones I made!

    http://jsperf.com/long-string-comparison/2

    I found two major results

    • When strings are identical performance is murdered; from ~9000000 ops/s to ~250 ops/sec (chrome)
    • The 64bit version of IE9 is much slower on my PC, results from the same tests:

      +------------+------------+
      | IE9 64bit  |  IE9 32bit |
      +------------+------------+
      | 4,270,414  | 8,667,472  |
      | 2,270,234  | 8,682,461  |
      +------------+------------+
      

    Sadly, jsperf logged both results as simply "IE 9".

    Even a precursory look at JS MD5 performance tells me that it is very, very slow (at least for large strings, see http://jsperf.com/md5-shootout/18 - peaks at 70 ops/sec). I would want to go as far as to try AJAXing the hash calculation or the comparison to the backend but I don't have time to test, sorry!

提交回复
热议问题