Performance of the compiled vs. interpreted javascript in java7 / Rhino

前端 未结 3 700
忘了有多久
忘了有多久 2020-12-29 13:45

I have a problem with performance of Rhino javascript engine in Java7, shortly - my script (that parses and compiles texts) runs in Chrome around 50-100 times quicker than t

3条回答
  •  没有蜡笔的小新
    2020-12-29 14:05

    It looks like i've found what is wrong - compilation used in 'my' code (actually taken from internet samples) has nothing to do with 'compiled'.

    Finally i've got to this link - https://developer.mozilla.org/en-US/docs/Rhino_JavaScript_Compiler - the Rhino's tool to compile .js into .class. I've got following result with the same JS code running compiled from .class's bytecode:

     time: 202ms, chars: 38890, sum: 2046720
     time: 92ms, chars: 38890, sum: 2046720
     time: 73ms, chars: 38890, sum: 2046720
     ...
     time: 71ms, chars: 38890, sum: 2046720
     time: 66ms, chars: 38890, sum: 2046720
     time: 64ms, chars: 38890, sum: 2046720
      ... 1143ms (per 15 iterations)
    
    --- sleep 5 secs ---
    
     time: 64ms, chars: 38890, sum: 2046720
     time: 52ms, chars: 38890, sum: 2046720
     time: 64ms, chars: 38890, sum: 2046720
     ...
     time: 62ms, chars: 38890, sum: 2046720
     time: 67ms, chars: 38890, sum: 2046720
     time: 67ms, chars: 38890, sum: 2046720
      ... 962ms
    
    
    --- sleep 5 secs ---
    
     time: 66ms, chars: 38890, sum: 2046720
     time: 56ms, chars: 38890, sum: 2046720
     time: 59ms, chars: 38890, sum: 2046720
     ...
     time: 69ms, chars: 38890, sum: 2046720
     time: 67ms, chars: 38890, sum: 2046720
     time: 59ms, chars: 38890, sum: 2046720
      ... 966ms
    

    (this is roughly 10 time quicker)

    and this is the result from Chrome:

     time: 5ms, chars: 38890, sum: 2046720
     time: 3ms, chars: 38890, sum: 2046720
     time: 1ms, chars: 38890, sum: 2046720
     time: 1ms, chars: 38890, sum: 2046720
     time: 1ms, chars: 38890, sum: 2046720
     time: 5ms, chars: 38890, sum: 2046720
     time: 0ms, chars: 38890, sum: 2046720
     time: 1ms, chars: 38890, sum: 2046720
     time: 1ms, chars: 38890, sum: 2046720
     time: 1ms, chars: 38890, sum: 2046720
    

    (average is 3-4 msec, ~15 quicker than compiled Java/Rhino, and ~200 times quicker than interpreted Java/Rhino).

提交回复
热议问题