Details

      Description

      Problem
      It seems that the generation of random numbers by Math.random() is not performing well. I've done an experiment where I generate random 8-char strings, and then I check the performance on Titanium, node and native iOS, and the results are quite conclusive. Find a detailed description of the experiment here: http://developer.appcelerator.com/question/153040/titanium-performance-generating-random-strings

      Test Case
      The experiment I did to test this lack of performance was the following: I coded the same random string generator algorithm in javascript and objC. This is how it looks in javascript:

      function randomId (length) {
      var textArray = [];
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
      for( var i=0; i < length; i++)
      textArray.push(possible.charAt(Math.floor(Math.random() * possible.length)));

      return textArray.join('');
      }

      Results
      And then I perform a test where I generate one million of 8-char strings using this algorithm, I store them in an array, and I check for duplicates. The results are:

      • When I run it with Titanium (iPhone simulator), I get an average of 40 repeated strings.
      • When I run it with node (same javascript code), I get NO repeated strings.
      • When I run it with XCode (the objC version of the algorithm) using the iPhone simulator, I get NO repeated strings.

      Conclusion
      It seems that there is an important lack of performance of the Math.random() method in the Titanium environment.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              clathrop Carter Lathrop
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-16633
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration