Beruflich Dokumente
Kultur Dokumente
JavaScript Games,
and Distributed Testing
John Resig
http://ejohn.org - http://twitter.com/jeresig
Measuring
Performance
Analyzing Performance
✦ Optimizing performance is a huge
concern: Faster code = happy users!
✦ Measure execution time
✦ Loop the code a few times
✦ Measure the difference:
✦ (new Date).getTime();
Stack Profiling
✦ jQuery Stack Profiler
✦ Look for problematic methods and plugins
✦ http://ejohn.org/blog/deep-profiling-
jquery-apps/
Accuracy of
JavaScript Time
We’re measuring the performance of
JavaScript from within JavaScript!
http://ejohn.org/blog/accuracy-of-javascript-time/
15ms intervals ONLY!
{
fireunit.getProfile(); "time": 8.443,
"calls": 611,
"data":[
{
"name":"makeArray()",
"calls":1,
"percent":23.58,
"ownTime":1.991,
"time":1.991,
"avgTime":1.991,
"minTime":1.991,
"maxTime":1.991,
"fileName":"jquery.js (line 2059)"
},
// etc.
http://ejohn.org/blog/function-call-profiling/ ]}
Complexity Analysis
✦ Analyze complexity rather than raw time
✦ jQuery Call Count Profiler (uses FireUnit)
Method Calls Big-O
.addClass("test"); 542 6n
.addClass("test"); 592 6n
.removeClass("test"); 754 8n
.removeClass("test"); 610 6n
.css("color", "red"); 495 5n
.css({color: "red", border: "1px 887 9n
solid red"});
.remove(); 23772 2n+n2
.append("<p>test</p>"); 307 3n
Complexity Analysis
✦ Reducing call count helps to reduce
complexity
✦ Results for 1.3.3:
Method Calls Big-O
.remove(); 298 3n
.html("<p>test</p>"); 507 5n
.empty(); 200 2n
http://ejohn.org/blog/function-call-profiling/
Why JavaScript
Games Are HARD
to Build
Browser-Based Games
✦ No installation required
✦ (Will be able to play at work!)
Why not Flash?
✦ JavaScript works everywhere
✦ Desktop
✦ iPhone / Mobile Device
✦ Wii
✦ OLPC
✦ http://warfish.net/
Nile Online
✦ http://www.playnileonline.com/
Strategy Games
✦ Very server-side heavy
✦ Most logic hidden from the user
✦ Hard to cheat
✦ Casual cheaters can’t change values
✦ Dedicated cheaters have to write full AI
Intelligence Games
✦ Player’s intelligence/knowledge challenged
✦ Games could be quick or slow-paced
✦ Easy to cheat
✦ Casual cheaters can open dictionary /
encyclopedia for answers
Word Twist
✦ http://wordtwist.org/
Babble
✦ http://playbabble.com/
Iron Sudoku
✦ http://ironsudoku.com/
Speed/Accuracy Games
✦ Require low latency
✦ Fast-paced and addictive
✦ JavaScript completely fails
✦ Garbage Collection cycles freeze the
browser
✦ None, or few, Accuracy-centric JavaScript
games
✦ Experienced coders can easily cheat
✦ (A bot to hit the keys at the right time)
Guitar Hero
http://ejohn.org/apps/hero/
Guitar Hero
✦ Heavily dependent upon accuracy
✦ (Hit the right notes at the right time)
✦ Real-time Boggle
✦ Head-to-head with other players
http://www.wordsplay.net/
Tringo
http://deepleap.org/
vs. Cheating
✦ All words are recorded with exact time
information
✦ Game is “played back” on the server to
verify score integrity using Server-Side JS
✦ TestSwarm
FF 3.5 FF 3.5 FF 3.5
IE 6
IE 6
FF 3 IE 6
Op 9
FF 3
IE 7
TestSwarm
IE 7