You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Justin Mclean <ju...@classsoftware.com> on 2013/10/18 03:17:53 UTC

UID performance

Hi,

This is about 2/3rds to twice as fast by my measurements (in Scout). Any one confirm?

Changes include.
- Use a string to store hex digits and charAt rather than array of ascii
- Use Array.join rather than String.fromCharCode
- Remove Math.floor as they are not required
- Set up static array and reuse that rather than creating new array each time

The timeString could probably be improved to remove the string manipulation but put the digits directly into the correct place into the array to save another 5% or so.

BYW any see where Number.toString is being called in there?

Any feedback?

Thanks,
Justin

diff --git a/frameworks/projects/framework/src/mx/utils/UIDUtil.as b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
index 4993563..576b598 100644
--- a/frameworks/projects/framework/src/mx/utils/UIDUtil.as
+++ b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
@@ -61,10 +61,16 @@ public class UIDUtil
 
     /**
      *  @private
-     *  Char codes for 0123456789ABCDEF
      */
-    private static const ALPHA_CHAR_CODES:Array = [48, 49, 50, 51, 52, 53, 54, 
-        55, 56, 57, 65, 66, 67, 68, 69, 70];
+	private static const CHAR_CODES:String = "0123456789ABCDEF";
+	
+	private static var EMPTYUID:Array = [
+		'0','0','0','0','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'0','0','0','0','0','0','0','0','0','0','0','0'
+	];
 
     //--------------------------------------------------------------------------
     //
@@ -106,53 +112,53 @@ public class UIDUtil
      *  @playerversion AIR 1.1
      *  @productversion Flex 3
      */
-    public static function createUID():String
-    {
-        var uid:Array = new Array(36);
-        var index:int = 0;
-        
-        var i:int;
-        var j:int;
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-
-        for (i = 0; i < 3; i++)
-        {
-            uid[index++] = 45; // charCode for "-"
-            
-            for (j = 0; j < 4; j++)
-            {
-                uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-            }
-        }
-        
-        uid[index++] = 45; // charCode for "-"
-
-        var time:Number = new Date().getTime();
-        // Note: time is the number of milliseconds since 1970,
-        // which is currently more than one trillion.
-        // We use the low 8 hex digits of this number in the UID.
-        // Just in case the system clock has been reset to
-        // Jan 1-4, 1970 (in which case this number could have only
-        // 1-7 hex digits), we pad on the left with 7 zeros
-        // before taking the low digits.
-        var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = timeString.charCodeAt(i);
-        }
-        
-        for (i = 0; i < 4; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-        
-        return String.fromCharCode.apply(null, uid);
-    }
+	public static function createUID():String
+	{
+		var uid:Array = EMPTYUID;
+		var index:int = 0;
+		
+		var i:int;
+		var j:int;
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+		}
+		
+		for (i = 0; i < 3; i++)
+		{
+			index++; // skip "-"
+			
+			for (j = 0; j < 4; j++)
+			{
+				uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+			}
+		}
+		
+		index++; // skip "-"
+		
+		var time:Number = new Date().getTime();
+		// Note: time is the number of milliseconds since 1970,
+		// which is currently more than one trillion.
+		// We use the low 8 hex digits of this number in the UID.
+		// Just in case the system clock has been reset to
+		// Jan 1-4, 1970 (in which case this number could have only
+		// 1-7 hex digits), we pad on the left with 7 zeros
+		// before taking the low digits.
+		var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = timeString.charAt(i);
+		}
+		
+		for (i = 0; i < 4; i++)
+		{
+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+		}
+		
+		return uid.join("");
+	}



RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Here is the code for the test:

public class UIDUtilTest
{

    static private const COUNT:int = 100000;

    [Test]
    public function benchCallNCreateUID_Original():void
    {

        var res:String;
        for (var i:int = 0; i < COUNT; i++)
            res = UIDUtil_Orig.createUID();
    }

    [Test]
    public function benchCallNCreateUID_JMcLean():void
    {

        var res:String;
        for (var i:int = 0; i < COUNT; i++)
            res = UIDUtil_JML.createUID();
    }
}

-----Message d'origine-----
De : Maurice Amsellem [mailto:maurice.amsellem@systar.com] 
Envoyé : vendredi 18 octobre 2013 09:02
À : dev@flex.apache.org
Objet : RE: UID performance

Hi, I have created simple test suite (in FlexUnit) with  original and new method functions,  calling 100K times createUID and the results are different for me:

-debug=true:
Old createUID : 2.652s
New createUID: 2.382s

-debug=false, optimize=true
Old createUID : 2.11s
New createUID: 1.878s

Config:  Windows 7, coreI7 , FP 11.8

Any one confirm ?

Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi 18 octobre 2013 03:18 À : dev@flex.apache.org Objet : UID performance

Hi,

This is about 2/3rds to twice as fast by my measurements (in Scout). Any one confirm?

Changes include.
- Use a string to store hex digits and charAt rather than array of ascii
- Use Array.join rather than String.fromCharCode
- Remove Math.floor as they are not required
- Set up static array and reuse that rather than creating new array each time

The timeString could probably be improved to remove the string manipulation but put the digits directly into the correct place into the array to save another 5% or so.

BYW any see where Number.toString is being called in there?

Any feedback?

Thanks,
Justin

diff --git a/frameworks/projects/framework/src/mx/utils/UIDUtil.as b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
index 4993563..576b598 100644
--- a/frameworks/projects/framework/src/mx/utils/UIDUtil.as
+++ b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
@@ -61,10 +61,16 @@ public class UIDUtil
 
     /**
      *  @private
-     *  Char codes for 0123456789ABCDEF
      */
-    private static const ALPHA_CHAR_CODES:Array = [48, 49, 50, 51, 52, 53, 54, 
-        55, 56, 57, 65, 66, 67, 68, 69, 70];
+	private static const CHAR_CODES:String = "0123456789ABCDEF";
+	
+	private static var EMPTYUID:Array = [
+		'0','0','0','0','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'0','0','0','0','0','0','0','0','0','0','0','0'
+	];
 
     //--------------------------------------------------------------------------
     //
@@ -106,53 +112,53 @@ public class UIDUtil
      *  @playerversion AIR 1.1
      *  @productversion Flex 3
      */
-    public static function createUID():String
-    {
-        var uid:Array = new Array(36);
-        var index:int = 0;
-        
-        var i:int;
-        var j:int;
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-
-        for (i = 0; i < 3; i++)
-        {
-            uid[index++] = 45; // charCode for "-"
-            
-            for (j = 0; j < 4; j++)
-            {
-                uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-            }
-        }
-        
-        uid[index++] = 45; // charCode for "-"
-
-        var time:Number = new Date().getTime();
-        // Note: time is the number of milliseconds since 1970,
-        // which is currently more than one trillion.
-        // We use the low 8 hex digits of this number in the UID.
-        // Just in case the system clock has been reset to
-        // Jan 1-4, 1970 (in which case this number could have only
-        // 1-7 hex digits), we pad on the left with 7 zeros
-        // before taking the low digits.
-        var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = timeString.charCodeAt(i);
-        }
-        
-        for (i = 0; i < 4; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-        
-        return String.fromCharCode.apply(null, uid);
-    }
+	public static function createUID():String
+	{
+		var uid:Array = EMPTYUID;
+		var index:int = 0;
+		
+		var i:int;
+		var j:int;
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+		}
+		
+		for (i = 0; i < 3; i++)
+		{
+			index++; // skip "-"
+			
+			for (j = 0; j < 4; j++)
+			{
+				uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+			}
+		}
+		
+		index++; // skip "-"
+		
+		var time:Number = new Date().getTime();
+		// Note: time is the number of milliseconds since 1970,
+		// which is currently more than one trillion.
+		// We use the low 8 hex digits of this number in the UID.
+		// Just in case the system clock has been reset to
+		// Jan 1-4, 1970 (in which case this number could have only
+		// 1-7 hex digits), we pad on the left with 7 zeros
+		// before taking the low digits.
+		var timeString:String = ("0000000" + 
+time.toString(16).toUpperCase()).substr(-8);
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = timeString.charAt(i);
+		}
+		
+		for (i = 0; i < 4; i++)
+		{
+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+		}
+		
+		return uid.join("");
+	}



AW: UID performance

Posted by "christofer.dutz@c-ware.de" <ch...@c-ware.de>.
I am currently using the 30 Day Trial of the Creative Cloud Service. In gengeral it seems possible to "purchase" Scout as part of the All In package, but I couldn't find a way to purchase it separately.

So that sucks :-(

Chris


________________________________________
Von: Maurice Amsellem [maurice.amsellem@systar.com]
Gesendet: Freitag, 18. Oktober 2013 10:26
An: dev@flex.apache.org
Betreff: RE: UID performance

I don't have Scout :-(

I have a premium FlashBuilder 4.7 licence.

Does it come with it, or is it a separate purchase?

Maurice

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com]
Envoyé : vendredi 18 octobre 2013 10:08
À : dev@flex.apache.org
Objet : Re: UID performance

Hi,

Well 10% or so is better than nothing.

Mind running though scout may be that getTime is more expensive on windows and skewing the results a little? I vaguely recall something about that in the past.

I tested on OSX.

Thanks,
Justin

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
> Scout is currently free with the free Creative Cloud account last time I checked.

I have subscribed for free to Creative Cloud and installed Scout.

Great tool (and nice looking).

Thanks for the info.

Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : vendredi 18 octobre 2013 11:08
À : dev@flex.apache.org
Objet : Re: UID performance

Hi,

> I don't have Scout :-(
Scout is currently free with the free Creative Cloud account last time I checked.

Thanks,
Justin

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Sorry, I don't see what you got.  Is there a screenshot or something ?

-----Message d'origine-----
De : Mark Kessler [mailto:kesslerconsulting@gmail.com] 
Envoyé : samedi 19 octobre 2013 01:51
À : Dev@Flex
Objet : Re: UID performance

I ran the swf file from your link and I got these...



On Fri, Oct 18, 2013 at 7:45 PM, Maurice Amsellem < maurice.amsellem@systar.com> wrote:

> I have posted FB project with the source s + compiled SWF.
>
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
> p 
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
> f
>
> Algorithm 1= Original
> Algorithm 2 = using Array.join() and other optimizations by JMcLean 
> Algo 3:  using single static byteArray (Maurice)
>
> These are the results I get for 100,000 iterations:
>
> Original: 2.74s
> V2:  2.5s
> V3:  1.70s
>
> Please can you test on your side as well...
>
> Maurice
>
> -----Message d'origine-----
> De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> Envoyé : samedi 19 octobre 2013 00:56
> À : dev@flex.apache.org
> Objet : RE: UID performance
>
> I have used a static ByteArray as suggested: much better.
> Thanks for the suggestion.
>
>
> -----Message d'origine-----
> De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> Envoyé : samedi 19 octobre 2013 00:49
> À : dev@flex.apache.org
> Objet : RE: UID performance
>
> Sure, I will do that.
>
> I will  also post the source so that you can recompile at your convenience.
>
> Maurice
>
>
> -----Message d'origine-----
> De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 
> 2013
> 00:13 À : dev@flex.apache.org Objet : Re: UID performance
>
> I'm a bit surprised that ByteArray.writeByte is faster but maybe 
> Array.join isn't that fast.  I would also like to see a test of a 
> single static bytearray and resetting it and/or overwriting the old bytes.
>
> Maybe if you put a SWF with various algorithms in your people.a.o 
> folder folks can hit it and make sure we all get the same results and 
> then we'll know which algorithm to check in.
>
> Thanks for this idea as well.
>
> -Alex
>
> On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
> wrote:
>
> >Any answer ?
> >
> >-----Message d'origine-----
> >De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
> >RE: UID performance
> >
> >Hi,
> >
> >I shouldn't have mixed the two options, because it's confusing.
> >
> >Actually, V3 option generates uppercase, exactly as the current UUID, 
> >and it's 2x faster.
> >So let's forget about V4...
> >
> >Here is the code:
> >
> >    private static const HEX_CHARS:String = "0123456789ABCDEF";
> >    private static const DASH:int = 45;  // "-"
> >
> >public static function createUID():String
> >    {
> >        var ba:ByteArray = new ByteArray();
> >        var i:int;
> >        var j:int;
> >
> >        for (i = 0; i < 8; i++) {
> >            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >       }
> >
> >        for (i = 0; i < 3; i++)
> >        {
> >            ba.writeByte(DASH);
> >            for (j = 0; j < 4; j++)
> >            {
> >                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >            }
> >        }
> >
> >        ba.writeByte(DASH);
> >
> >        var time:Number = new Date().getTime();
> >
> >        var timeString:String = ("0000000" + 
> >time.toString(16).toUpperCase()).substr(-8);
> >        ba.writeUTFBytes(timeString);
> >
> >        for (i = 0; i < 4; i++)
> >        {
> >            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >        }
> >
> >        return ba.toString();
> >    }
> >
> >-----Message d'origine-----
> >De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : 
> >vendredi
> >18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
> >performance
> >
> >Hi,
> >
> >> V3: generates the random hex bytes one by one, and writes them to 
> >> the BA
> >> V4: generates 4 or 8 random bytes in one shot, and writes them to 
> >> the BA  (hexa in lowercase, to avoid call toUppercase() )
> >Probably best not too fiddle too much with the UID construction. 
> >While I can't think of any major issues it would cause there could be 
> >subtle issues due to seeding of random numbers and the like.
> >
> >> I don't know if this is acceptable (are we breaking some code if we 
> >>use lowercase instead of uppercase).
> >
> >Again can't think of any issues but probably safer if we kept it 
> >upper case.
> >
> >Go ahead and post the code it could be interesting/useful to someone.
> >
> >Thanks,
> >Justin
>
>

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Ok thanks.  

When running with Chrome, I am getting other figures:

1.3
1.26
0.42

That's weird !!

-----Message d'origine-----
De : Mark Kessler [mailto:kesslerconsulting@gmail.com] 
Envoyé : samedi 19 octobre 2013 01:51
À : Dev@Flex
Objet : Re: UID performance

2.11s
1.93s
1.32s


On Fri, Oct 18, 2013 at 7:50 PM, Mark Kessler
<ke...@gmail.com>wrote:

> I ran the swf file from your link and I got these...
>
>
>

Re: UID performance

Posted by Mark Kessler <ke...@gmail.com>.
2.11s
1.93s
1.32s


On Fri, Oct 18, 2013 at 7:50 PM, Mark Kessler
<ke...@gmail.com>wrote:

> I ran the swf file from your link and I got these...
>
>
>

Re: UID performance

Posted by Mark Kessler <ke...@gmail.com>.
I ran the swf file from your link and I got these...



On Fri, Oct 18, 2013 at 7:45 PM, Maurice Amsellem <
maurice.amsellem@systar.com> wrote:

> I have posted FB project with the source s + compiled SWF.
>
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fxp
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.swf
>
> Algorithm 1= Original
> Algorithm 2 = using Array.join() and other optimizations by JMcLean
> Algo 3:  using single static byteArray (Maurice)
>
> These are the results I get for 100,000 iterations:
>
> Original: 2.74s
> V2:  2.5s
> V3:  1.70s
>
> Please can you test on your side as well...
>
> Maurice
>
> -----Message d'origine-----
> De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> Envoyé : samedi 19 octobre 2013 00:56
> À : dev@flex.apache.org
> Objet : RE: UID performance
>
> I have used a static ByteArray as suggested: much better.
> Thanks for the suggestion.
>
>
> -----Message d'origine-----
> De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> Envoyé : samedi 19 octobre 2013 00:49
> À : dev@flex.apache.org
> Objet : RE: UID performance
>
> Sure, I will do that.
>
> I will  also post the source so that you can recompile at your convenience.
>
> Maurice
>
>
> -----Message d'origine-----
> De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013
> 00:13 À : dev@flex.apache.org Objet : Re: UID performance
>
> I'm a bit surprised that ByteArray.writeByte is faster but maybe
> Array.join isn't that fast.  I would also like to see a test of a single
> static bytearray and resetting it and/or overwriting the old bytes.
>
> Maybe if you put a SWF with various algorithms in your people.a.o folder
> folks can hit it and make sure we all get the same results and then we'll
> know which algorithm to check in.
>
> Thanks for this idea as well.
>
> -Alex
>
> On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
> wrote:
>
> >Any answer ?
> >
> >-----Message d'origine-----
> >De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
> >RE: UID performance
> >
> >Hi,
> >
> >I shouldn't have mixed the two options, because it's confusing.
> >
> >Actually, V3 option generates uppercase, exactly as the current UUID,
> >and it's 2x faster.
> >So let's forget about V4...
> >
> >Here is the code:
> >
> >    private static const HEX_CHARS:String = "0123456789ABCDEF";
> >    private static const DASH:int = 45;  // "-"
> >
> >public static function createUID():String
> >    {
> >        var ba:ByteArray = new ByteArray();
> >        var i:int;
> >        var j:int;
> >
> >        for (i = 0; i < 8; i++) {
> >            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >       }
> >
> >        for (i = 0; i < 3; i++)
> >        {
> >            ba.writeByte(DASH);
> >            for (j = 0; j < 4; j++)
> >            {
> >                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >            }
> >        }
> >
> >        ba.writeByte(DASH);
> >
> >        var time:Number = new Date().getTime();
> >
> >        var timeString:String = ("0000000" +
> >time.toString(16).toUpperCase()).substr(-8);
> >        ba.writeUTFBytes(timeString);
> >
> >        for (i = 0; i < 4; i++)
> >        {
> >            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >        }
> >
> >        return ba.toString();
> >    }
> >
> >-----Message d'origine-----
> >De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi
> >18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
> >performance
> >
> >Hi,
> >
> >> V3: generates the random hex bytes one by one, and writes them to the
> >> BA
> >> V4: generates 4 or 8 random bytes in one shot, and writes them to the
> >> BA  (hexa in lowercase, to avoid call toUppercase() )
> >Probably best not too fiddle too much with the UID construction. While
> >I can't think of any major issues it would cause there could be subtle
> >issues due to seeding of random numbers and the like.
> >
> >> I don't know if this is acceptable (are we breaking some code if we
> >>use lowercase instead of uppercase).
> >
> >Again can't think of any issues but probably safer if we kept it upper
> >case.
> >
> >Go ahead and post the code it could be interesting/useful to someone.
> >
> >Thanks,
> >Justin
>
>

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Thanks Alex.

-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] 
Envoyé : samedi 19 octobre 2013 02:05
À : dev@flex.apache.org
Objet : Re: UID performance

Thanks for providing the release SWF.  For me the results are even better:

Win7 Chrome FP11.8 release player

1.39s
1.29s
0.430s

That's better than 2x, more like 3x where in the debugger player it wasn't quite 2x.

Excellent job!
-Alex

On 10/18/13 4:58 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>I tried already and the results are consistent.
>
>Here is the link:
>
>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_rel
>eas
>e.swf
>
>Maurice
>
>-----Message d'origine-----
>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 
>2013 01:56 À : dev@flex.apache.org Objet : Re: UID performance
>
>Actually, I thought of one more test that needs to be run which I don't 
>have time to do right now: Release player with release SWF.  Sometimes 
>you can get very different results on the debugger players.
>
>Thanks,
>-Alex
>
>On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
>
>>Yup, V3 wins on mac and windows for me.
>>
>>Thanks for doing it.
>>
>>-Alex
>>
>>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>I have posted FB project with the source s + compiled SWF.
>>>
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.f
>>>x
>>>p
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.s
>>>w
>>>f
>>>
>>>Algorithm 1= Original
>>>Algorithm 2 = using Array.join() and other optimizations by JMcLean 
>>>Algo 3:  using single static byteArray (Maurice)
>>>
>>>These are the results I get for 100,000 iterations:
>>>
>>>Original: 2.74s
>>>V2:  2.5s
>>>V3:  1.70s
>>>
>>>Please can you test on your side as well...
>>>
>>>Maurice
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:56 À : dev@flex.apache.org Objet : 
>>>RE: UID performance
>>>
>>>I have used a static ByteArray as suggested: much better.
>>>Thanks for the suggestion.
>>>
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:49 À : dev@flex.apache.org Objet : 
>>>RE: UID performance
>>>
>>>Sure, I will do that.
>>>
>>>I will  also post the source so that you can recompile at your 
>>>convenience.
>>>
>>>Maurice
>>>
>>>
>>>-----Message d'origine-----
>>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
>>>2013
>>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>>
>>>I'm a bit surprised that ByteArray.writeByte is faster but maybe 
>>>Array.join isn't that fast.  I would also like to see a test of a 
>>>single static bytearray and resetting it and/or overwriting the old 
>>>bytes.
>>>
>>>Maybe if you put a SWF with various algorithms in your people.a.o 
>>>folder folks can hit it and make sure we all get the same results and 
>>>then we'll know which algorithm to check in.
>>>
>>>Thanks for this idea as well.
>>>
>>>-Alex
>>>
>>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>>wrote:
>>>
>>>>Any answer ? 
>>>>
>>>>-----Message d'origine-----
>>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>>RE: UID performance
>>>>
>>>>Hi,
>>>>
>>>>I shouldn't have mixed the two options, because it's confusing.
>>>>
>>>>Actually, V3 option generates uppercase, exactly as the current 
>>>>UUID, and it's 2x faster.
>>>>So let's forget about V4...
>>>>
>>>>Here is the code:
>>>>
>>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>>    private static const DASH:int = 45;  // "-"
>>>>
>>>>public static function createUID():String
>>>>    {
>>>>        var ba:ByteArray = new ByteArray();
>>>>        var i:int;
>>>>        var j:int;
>>>>
>>>>        for (i = 0; i < 8; i++) {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>       }
>>>>
>>>>        for (i = 0; i < 3; i++)
>>>>        {
>>>>            ba.writeByte(DASH);
>>>>            for (j = 0; j < 4; j++)
>>>>            {
>>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>            }
>>>>        }
>>>>
>>>>        ba.writeByte(DASH);
>>>>
>>>>        var time:Number = new Date().getTime();
>>>>
>>>>        var timeString:String = ("0000000" + 
>>>>time.toString(16).toUpperCase()).substr(-8);
>>>>        ba.writeUTFBytes(timeString);
>>>>
>>>>        for (i = 0; i < 4; i++)
>>>>        {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>        }
>>>>
>>>>        return ba.toString();
>>>>    }
>>>>
>>>>-----Message d'origine-----
>>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
>>>>vendredi
>>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>>>>performance
>>>>
>>>>Hi,
>>>>
>>>>> V3: generates the random hex bytes one by one, and writes them to 
>>>>> the BA
>>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to 
>>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>>>>Probably best not too fiddle too much with the UID construction.
>>>>While I can't think of any major issues it would cause there could 
>>>>be subtle issues due to seeding of random numbers and the like.
>>>>
>>>>> I don't know if this is acceptable (are we breaking some code if 
>>>>>we use lowercase instead of uppercase).
>>>>
>>>>Again can't think of any issues but probably safer if we kept it 
>>>>upper case.
>>>>
>>>>Go ahead and post the code it could be interesting/useful to someone.
>>>>
>>>>Thanks,
>>>>Justin
>>>
>>
>


Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.

On 10/18/13 5:45 PM, "João Fernandes"
<jo...@gmail.com> wrote:

>Chrome Flash Pepper reports
>V1 0.891s
>V2 0.828s
>V3 0.276s
>
>Great results! This will clearly improve large ArrayCollections
>deserialization! Thank you for this!
True, but implementing IUID should still be faster.  And lazy
deserialization even faster in many cases.

-Alex


Re: UID performance

Posted by João Fernandes <jo...@gmail.com>.
Chrome Flash Pepper reports
V1 0.891s
V2 0.828s
V3 0.276s

Great results! This will clearly improve large ArrayCollections
deserialization! Thank you for this!


On 19 October 2013 01:12, Maurice Amsellem <ma...@systar.com>wrote:

> Forgot about this :-(
> You are right,  FF is running debugger version of FP, so that explains the
> difference.
> Thanks for the check.
>
> BTW, thanks also for the static recycled ByteArray idea, this is an easy
> and efficient optimization that I could also use in my own code.
>
> Maurice
>
> -----Message d'origine-----
> De : Alex Harui [mailto:aharui@adobe.com]
> Envoyé : samedi 19 octobre 2013 02:07
> À : dev@flex.apache.org
> Objet : Re: UID performance
>
> I assume you double-checked in flashplayerversion.com that FF is running
> a release player?
>
> It could be that bytearray got optimized over time as it was a key piece
> of gaming strategy and Alchemy.
>
> -Alex
>
> On 10/18/13 5:04 PM, "Maurice Amsellem" <ma...@systar.com>
> wrote:
>
> >FYI, I tried with Chrome (FP 11.9) and Firefox (FP 11.4) and the
> >results are quite different:
> >
> >Chrome FP 11.9:
> >1.29
> >1.24
> >0.405
> >
> >FireFox FP 11.4:
> >2.16
> >1.93
> >1.07
> >
> >Is the difference expected ? That is, is FP 11.9 twice as fast as FP
> >11.4, or is it just for these computations.
> >
> >Maurice
> >
> >-----Message d'origine-----
> >De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >Envoyé : samedi 19 octobre 2013 01:59
> >À : dev@flex.apache.org
> >Objet : RE: UID performance
> >
> >I tried already and the results are consistent.
> >
> >Here is the link:
> >
> >https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_rel
> >eas
> >e.swf
> >
> >Maurice
> >
> >-----Message d'origine-----
> >De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
> >2013
> >01:56 À : dev@flex.apache.org Objet : Re: UID performance
> >
> >Actually, I thought of one more test that needs to be run which I don't
> >have time to do right now: Release player with release SWF.  Sometimes
> >you can get very different results on the debugger players.
> >
> >Thanks,
> >-Alex
> >
> >On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
> >
> >>Yup, V3 wins on mac and windows for me.
> >>
> >>Thanks for doing it.
> >>
> >>-Alex
> >>
> >>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
> >>wrote:
> >>
> >>>I have posted FB project with the source s + compiled SWF.
> >>>
> >>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.f
> >>>x
> >>>p
> >>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.s
> >>>w
> >>>f
> >>>
> >>>Algorithm 1= Original
> >>>Algorithm 2 = using Array.join() and other optimizations by JMcLean
> >>>Algo 3:  using single static byteArray (Maurice)
> >>>
> >>>These are the results I get for 100,000 iterations:
> >>>
> >>>Original: 2.74s
> >>>V2:  2.5s
> >>>V3:  1.70s
> >>>
> >>>Please can you test on your side as well...
> >>>
> >>>Maurice
> >>>
> >>>-----Message d'origine-----
> >>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >>>Envoyé : samedi 19 octobre 2013 00:56 À : dev@flex.apache.org Objet :
> >>>RE: UID performance
> >>>
> >>>I have used a static ByteArray as suggested: much better.
> >>>Thanks for the suggestion.
> >>>
> >>>
> >>>-----Message d'origine-----
> >>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >>>Envoyé : samedi 19 octobre 2013 00:49 À : dev@flex.apache.org Objet :
> >>>RE: UID performance
> >>>
> >>>Sure, I will do that.
> >>>
> >>>I will  also post the source so that you can recompile at your
> >>>convenience.
> >>>
> >>>Maurice
> >>>
> >>>
> >>>-----Message d'origine-----
> >>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
> >>>2013
> >>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
> >>>
> >>>I'm a bit surprised that ByteArray.writeByte is faster but maybe
> >>>Array.join isn't that fast.  I would also like to see a test of a
> >>>single static bytearray and resetting it and/or overwriting the old
> >>>bytes.
> >>>
> >>>Maybe if you put a SWF with various algorithms in your people.a.o
> >>>folder folks can hit it and make sure we all get the same results and
> >>>then we'll know which algorithm to check in.
> >>>
> >>>Thanks for this idea as well.
> >>>
> >>>-Alex
> >>>
> >>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
> >>>wrote:
> >>>
> >>>>Any answer ?
> >>>>
> >>>>-----Message d'origine-----
> >>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet
> :
> >>>>RE: UID performance
> >>>>
> >>>>Hi,
> >>>>
> >>>>I shouldn't have mixed the two options, because it's confusing.
> >>>>
> >>>>Actually, V3 option generates uppercase, exactly as the current
> >>>>UUID, and it's 2x faster.
> >>>>So let's forget about V4...
> >>>>
> >>>>Here is the code:
> >>>>
> >>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
> >>>>    private static const DASH:int = 45;  // "-"
> >>>>
> >>>>public static function createUID():String
> >>>>    {
> >>>>        var ba:ByteArray = new ByteArray();
> >>>>        var i:int;
> >>>>        var j:int;
> >>>>
> >>>>        for (i = 0; i < 8; i++) {
> >>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >>>>       }
> >>>>
> >>>>        for (i = 0; i < 3; i++)
> >>>>        {
> >>>>            ba.writeByte(DASH);
> >>>>            for (j = 0; j < 4; j++)
> >>>>            {
> >>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >>>>            }
> >>>>        }
> >>>>
> >>>>        ba.writeByte(DASH);
> >>>>
> >>>>        var time:Number = new Date().getTime();
> >>>>
> >>>>        var timeString:String = ("0000000" +
> >>>>time.toString(16).toUpperCase()).substr(-8);
> >>>>        ba.writeUTFBytes(timeString);
> >>>>
> >>>>        for (i = 0; i < 4; i++)
> >>>>        {
> >>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >>>>        }
> >>>>
> >>>>        return ba.toString();
> >>>>    }
> >>>>
> >>>>-----Message d'origine-----
> >>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
> >>>>vendredi
> >>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
> >>>>performance
> >>>>
> >>>>Hi,
> >>>>
> >>>>> V3: generates the random hex bytes one by one, and writes them to
> >>>>> the BA
> >>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to
> >>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
> >>>>Probably best not too fiddle too much with the UID construction.
> >>>>While I can't think of any major issues it would cause there could
> >>>>be subtle issues due to seeding of random numbers and the like.
> >>>>
> >>>>> I don't know if this is acceptable (are we breaking some code if
> >>>>>we use lowercase instead of uppercase).
> >>>>
> >>>>Again can't think of any issues but probably safer if we kept it
> >>>>upper case.
> >>>>
> >>>>Go ahead and post the code it could be interesting/useful to someone.
> >>>>
> >>>>Thanks,
> >>>>Justin
> >>>
> >>
> >
>
>


-- 

João Fernandes

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Forgot about this :-(
You are right,  FF is running debugger version of FP, so that explains the difference.
Thanks for the check. 

BTW, thanks also for the static recycled ByteArray idea, this is an easy and efficient optimization that I could also use in my own code.

Maurice 

-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] 
Envoyé : samedi 19 octobre 2013 02:07
À : dev@flex.apache.org
Objet : Re: UID performance

I assume you double-checked in flashplayerversion.com that FF is running a release player?

It could be that bytearray got optimized over time as it was a key piece of gaming strategy and Alchemy.

-Alex

On 10/18/13 5:04 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>FYI, I tried with Chrome (FP 11.9) and Firefox (FP 11.4) and the 
>results are quite different:
>
>Chrome FP 11.9:
>1.29
>1.24
>0.405
>
>FireFox FP 11.4:
>2.16
>1.93
>1.07
>
>Is the difference expected ? That is, is FP 11.9 twice as fast as FP 
>11.4, or is it just for these computations.
>
>Maurice
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : samedi 19 octobre 2013 01:59
>À : dev@flex.apache.org
>Objet : RE: UID performance
>
>I tried already and the results are consistent.
>
>Here is the link:
>
>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_rel
>eas
>e.swf
>
>Maurice
>
>-----Message d'origine-----
>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 
>2013
>01:56 À : dev@flex.apache.org Objet : Re: UID performance
>
>Actually, I thought of one more test that needs to be run which I don't 
>have time to do right now: Release player with release SWF.  Sometimes 
>you can get very different results on the debugger players.
>
>Thanks,
>-Alex
>
>On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
>
>>Yup, V3 wins on mac and windows for me.
>>
>>Thanks for doing it.
>>
>>-Alex
>>
>>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>I have posted FB project with the source s + compiled SWF.
>>>
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.f
>>>x
>>>p
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.s
>>>w
>>>f
>>>
>>>Algorithm 1= Original
>>>Algorithm 2 = using Array.join() and other optimizations by JMcLean 
>>>Algo 3:  using single static byteArray (Maurice)
>>>
>>>These are the results I get for 100,000 iterations:
>>>
>>>Original: 2.74s
>>>V2:  2.5s
>>>V3:  1.70s
>>>
>>>Please can you test on your side as well...
>>>
>>>Maurice
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:56 À : dev@flex.apache.org Objet : 
>>>RE: UID performance
>>>
>>>I have used a static ByteArray as suggested: much better.
>>>Thanks for the suggestion.
>>>
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:49 À : dev@flex.apache.org Objet : 
>>>RE: UID performance
>>>
>>>Sure, I will do that.
>>>
>>>I will  also post the source so that you can recompile at your 
>>>convenience.
>>>
>>>Maurice
>>>
>>>
>>>-----Message d'origine-----
>>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
>>>2013
>>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>>
>>>I'm a bit surprised that ByteArray.writeByte is faster but maybe 
>>>Array.join isn't that fast.  I would also like to see a test of a 
>>>single static bytearray and resetting it and/or overwriting the old 
>>>bytes.
>>>
>>>Maybe if you put a SWF with various algorithms in your people.a.o 
>>>folder folks can hit it and make sure we all get the same results and 
>>>then we'll know which algorithm to check in.
>>>
>>>Thanks for this idea as well.
>>>
>>>-Alex
>>>
>>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>>wrote:
>>>
>>>>Any answer ? 
>>>>
>>>>-----Message d'origine-----
>>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>>RE: UID performance
>>>>
>>>>Hi,
>>>>
>>>>I shouldn't have mixed the two options, because it's confusing.
>>>>
>>>>Actually, V3 option generates uppercase, exactly as the current 
>>>>UUID, and it's 2x faster.
>>>>So let's forget about V4...
>>>>
>>>>Here is the code:
>>>>
>>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>>    private static const DASH:int = 45;  // "-"
>>>>
>>>>public static function createUID():String
>>>>    {
>>>>        var ba:ByteArray = new ByteArray();
>>>>        var i:int;
>>>>        var j:int;
>>>>
>>>>        for (i = 0; i < 8; i++) {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>       }
>>>>
>>>>        for (i = 0; i < 3; i++)
>>>>        {
>>>>            ba.writeByte(DASH);
>>>>            for (j = 0; j < 4; j++)
>>>>            {
>>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>            }
>>>>        }
>>>>
>>>>        ba.writeByte(DASH);
>>>>
>>>>        var time:Number = new Date().getTime();
>>>>
>>>>        var timeString:String = ("0000000" + 
>>>>time.toString(16).toUpperCase()).substr(-8);
>>>>        ba.writeUTFBytes(timeString);
>>>>
>>>>        for (i = 0; i < 4; i++)
>>>>        {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>        }
>>>>
>>>>        return ba.toString();
>>>>    }
>>>>
>>>>-----Message d'origine-----
>>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
>>>>vendredi
>>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>>>>performance
>>>>
>>>>Hi,
>>>>
>>>>> V3: generates the random hex bytes one by one, and writes them to 
>>>>> the BA
>>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to 
>>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>>>>Probably best not too fiddle too much with the UID construction.
>>>>While I can't think of any major issues it would cause there could 
>>>>be subtle issues due to seeding of random numbers and the like.
>>>>
>>>>> I don't know if this is acceptable (are we breaking some code if 
>>>>>we use lowercase instead of uppercase).
>>>>
>>>>Again can't think of any issues but probably safer if we kept it 
>>>>upper case.
>>>>
>>>>Go ahead and post the code it could be interesting/useful to someone.
>>>>
>>>>Thanks,
>>>>Justin
>>>
>>
>


Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
I assume you double-checked in flashplayerversion.com that FF is running a
release player?

It could be that bytearray got optimized over time as it was a key piece
of gaming strategy and Alchemy.

-Alex

On 10/18/13 5:04 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>FYI, I tried with Chrome (FP 11.9) and Firefox (FP 11.4) and the results
>are quite different:
>
>Chrome FP 11.9:
>1.29
>1.24
>0.405
>
>FireFox FP 11.4:
>2.16
>1.93
>1.07
>
>Is the difference expected ? That is, is FP 11.9 twice as fast as FP
>11.4, or is it just for these computations.
>
>Maurice 
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : samedi 19 octobre 2013 01:59
>À : dev@flex.apache.org
>Objet : RE: UID performance
>
>I tried already and the results are consistent.
>
>Here is the link:
>
>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_releas
>e.swf
>
>Maurice 
>
>-----Message d'origine-----
>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013
>01:56 À : dev@flex.apache.org Objet : Re: UID performance
>
>Actually, I thought of one more test that needs to be run which I don't
>have time to do right now: Release player with release SWF.  Sometimes
>you can get very different results on the debugger players.
>
>Thanks,
>-Alex
>
>On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
>
>>Yup, V3 wins on mac and windows for me.
>>
>>Thanks for doing it.
>>
>>-Alex
>>
>>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>I have posted FB project with the source s + compiled SWF.
>>>
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
>>>p
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
>>>f
>>>
>>>Algorithm 1= Original
>>>Algorithm 2 = using Array.join() and other optimizations by JMcLean
>>>Algo 3:  using single static byteArray (Maurice)
>>>
>>>These are the results I get for 100,000 iterations:
>>>
>>>Original: 2.74s
>>>V2:  2.5s
>>>V3:  1.70s
>>>
>>>Please can you test on your side as well...
>>>
>>>Maurice
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:56
>>>À : dev@flex.apache.org
>>>Objet : RE: UID performance
>>>
>>>I have used a static ByteArray as suggested: much better.
>>>Thanks for the suggestion.
>>>
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:49
>>>À : dev@flex.apache.org
>>>Objet : RE: UID performance
>>>
>>>Sure, I will do that.
>>>
>>>I will  also post the source so that you can recompile at your
>>>convenience.
>>>
>>>Maurice
>>>
>>>
>>>-----Message d'origine-----
>>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
>>>2013
>>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>>
>>>I'm a bit surprised that ByteArray.writeByte is faster but maybe
>>>Array.join isn't that fast.  I would also like to see a test of a
>>>single static bytearray and resetting it and/or overwriting the old
>>>bytes.
>>>
>>>Maybe if you put a SWF with various algorithms in your people.a.o
>>>folder folks can hit it and make sure we all get the same results and
>>>then we'll know which algorithm to check in.
>>>
>>>Thanks for this idea as well.
>>>
>>>-Alex
>>>
>>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>>wrote:
>>>
>>>>Any answer ? 
>>>>
>>>>-----Message d'origine-----
>>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>>RE: UID performance
>>>>
>>>>Hi,
>>>>
>>>>I shouldn't have mixed the two options, because it's confusing.
>>>>
>>>>Actually, V3 option generates uppercase, exactly as the current UUID,
>>>>and it's 2x faster.
>>>>So let's forget about V4...
>>>>
>>>>Here is the code:
>>>>
>>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>>    private static const DASH:int = 45;  // "-"
>>>>
>>>>public static function createUID():String
>>>>    {
>>>>        var ba:ByteArray = new ByteArray();
>>>>        var i:int;
>>>>        var j:int;
>>>>
>>>>        for (i = 0; i < 8; i++) {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>       }
>>>>
>>>>        for (i = 0; i < 3; i++)
>>>>        {
>>>>            ba.writeByte(DASH);
>>>>            for (j = 0; j < 4; j++)
>>>>            {
>>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>            }
>>>>        }
>>>>
>>>>        ba.writeByte(DASH);
>>>>
>>>>        var time:Number = new Date().getTime();
>>>>
>>>>        var timeString:String = ("0000000" +
>>>>time.toString(16).toUpperCase()).substr(-8);
>>>>        ba.writeUTFBytes(timeString);
>>>>
>>>>        for (i = 0; i < 4; i++)
>>>>        {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>        }
>>>>
>>>>        return ba.toString();
>>>>    }
>>>>
>>>>-----Message d'origine-----
>>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
>>>>vendredi
>>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
>>>>performance
>>>>
>>>>Hi,
>>>>
>>>>> V3: generates the random hex bytes one by one, and writes them to
>>>>> the BA
>>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to
>>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>>>>Probably best not too fiddle too much with the UID construction.
>>>>While I can't think of any major issues it would cause there could be
>>>>subtle issues due to seeding of random numbers and the like.
>>>>
>>>>> I don't know if this is acceptable (are we breaking some code if we
>>>>>use lowercase instead of uppercase).
>>>>
>>>>Again can't think of any issues but probably safer if we kept it
>>>>upper case.
>>>>
>>>>Go ahead and post the code it could be interesting/useful to someone.
>>>>
>>>>Thanks,
>>>>Justin
>>>
>>
>


RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
FYI, I tried with Chrome (FP 11.9) and Firefox (FP 11.4) and the results are quite different:

Chrome FP 11.9:
1.29
1.24
0.405

FireFox FP 11.4:
2.16
1.93
1.07

Is the difference expected ? That is, is FP 11.9 twice as fast as FP 11.4, or is it just for these computations.

Maurice 

-----Message d'origine-----
De : Maurice Amsellem [mailto:maurice.amsellem@systar.com] 
Envoyé : samedi 19 octobre 2013 01:59
À : dev@flex.apache.org
Objet : RE: UID performance

I tried already and the results are consistent.

Here is the link:

https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_release.swf

Maurice 

-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013 01:56 À : dev@flex.apache.org Objet : Re: UID performance

Actually, I thought of one more test that needs to be run which I don't have time to do right now: Release player with release SWF.  Sometimes you can get very different results on the debugger players.

Thanks,
-Alex

On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:

>Yup, V3 wins on mac and windows for me.
>
>Thanks for doing it.
>
>-Alex
>
>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>wrote:
>
>>I have posted FB project with the source s + compiled SWF.
>>
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
>>p
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
>>f
>>
>>Algorithm 1= Original
>>Algorithm 2 = using Array.join() and other optimizations by JMcLean 
>>Algo 3:  using single static byteArray (Maurice)
>>
>>These are the results I get for 100,000 iterations:
>>
>>Original: 2.74s
>>V2:  2.5s
>>V3:  1.70s
>>
>>Please can you test on your side as well...
>>
>>Maurice
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : samedi 19 octobre 2013 00:56
>>À : dev@flex.apache.org
>>Objet : RE: UID performance
>>
>>I have used a static ByteArray as suggested: much better.
>>Thanks for the suggestion.
>>
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : samedi 19 octobre 2013 00:49
>>À : dev@flex.apache.org
>>Objet : RE: UID performance
>>
>>Sure, I will do that.
>>
>>I will  also post the source so that you can recompile at your 
>>convenience.
>>
>>Maurice
>>
>>
>>-----Message d'origine-----
>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
>>2013
>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>
>>I'm a bit surprised that ByteArray.writeByte is faster but maybe 
>>Array.join isn't that fast.  I would also like to see a test of a 
>>single static bytearray and resetting it and/or overwriting the old bytes.
>>
>>Maybe if you put a SWF with various algorithms in your people.a.o 
>>folder folks can hit it and make sure we all get the same results and 
>>then we'll know which algorithm to check in.
>>
>>Thanks for this idea as well.
>>
>>-Alex
>>
>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>Any answer ? 
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>RE: UID performance
>>>
>>>Hi,
>>>
>>>I shouldn't have mixed the two options, because it's confusing.
>>>
>>>Actually, V3 option generates uppercase, exactly as the current UUID, 
>>>and it's 2x faster.
>>>So let's forget about V4...
>>>
>>>Here is the code:
>>>
>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>    private static const DASH:int = 45;  // "-"
>>>
>>>public static function createUID():String
>>>    {
>>>        var ba:ByteArray = new ByteArray();
>>>        var i:int;
>>>        var j:int;
>>>
>>>        for (i = 0; i < 8; i++) {
>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>       }
>>>
>>>        for (i = 0; i < 3; i++)
>>>        {
>>>            ba.writeByte(DASH);
>>>            for (j = 0; j < 4; j++)
>>>            {
>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>            }
>>>        }
>>>
>>>        ba.writeByte(DASH);
>>>
>>>        var time:Number = new Date().getTime();
>>>
>>>        var timeString:String = ("0000000" + 
>>>time.toString(16).toUpperCase()).substr(-8);
>>>        ba.writeUTFBytes(timeString);
>>>
>>>        for (i = 0; i < 4; i++)
>>>        {
>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>        }
>>>
>>>        return ba.toString();
>>>    }
>>>
>>>-----Message d'origine-----
>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : 
>>>vendredi
>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>>>performance
>>>
>>>Hi,
>>>
>>>> V3: generates the random hex bytes one by one, and writes them to 
>>>> the BA
>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to 
>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>>>Probably best not too fiddle too much with the UID construction. 
>>>While I can't think of any major issues it would cause there could be 
>>>subtle issues due to seeding of random numbers and the like.
>>>
>>>> I don't know if this is acceptable (are we breaking some code if we 
>>>>use lowercase instead of uppercase).
>>>
>>>Again can't think of any issues but probably safer if we kept it 
>>>upper case.
>>>
>>>Go ahead and post the code it could be interesting/useful to someone.
>>>
>>>Thanks,
>>>Justin
>>
>


Re: UID performance

Posted by Mark Kessler <ke...@gmail.com>.
I know but I wasn't expecting that much while still using my debug player.


On Fri, Oct 18, 2013 at 8:09 PM, Alex Harui <ah...@adobe.com> wrote:

> A release SWF should outperform a debug SWF, so that's expected.
>
> On 10/18/13 5:07 PM, "Mark Kessler" <ke...@gmail.com> wrote:
>
> >That newer link gives me faster results... lol
> >
> >1.71s
> >1.54s
> >0.903s
> >
> >
> >
> >On Fri, Oct 18, 2013 at 7:58 PM, Maurice Amsellem <
> >maurice.amsellem@systar.com> wrote:
> >
> >> I tried already and the results are consistent.
> >>
> >> Here is the link:
> >>
> >>
> >>
> >>
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_relea
> >>se.swf
> >>
> >> Maurice
> >>
> >> -----Message d'origine-----
> >> De : Alex Harui [mailto:aharui@adobe.com]
> >> Envoyé : samedi 19 octobre 2013 01:56
> >> À : dev@flex.apache.org
> >> Objet : Re: UID performance
> >>
> >> Actually, I thought of one more test that needs to be run which I don't
> >> have time to do right now: Release player with release SWF.  Sometimes
> >>you
> >> can get very different results on the debugger players.
> >>
> >> Thanks,
> >> -Alex
> >>
> >> On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
> >>
> >> >Yup, V3 wins on mac and windows for me.
> >> >
> >> >Thanks for doing it.
> >> >
> >> >-Alex
> >> >
> >> >On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
> >> >wrote:
> >> >
> >> >>I have posted FB project with the source s + compiled SWF.
> >> >>
> >> >>
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
> >> >>p
> >> >>
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
> >> >>f
> >> >>
> >> >>Algorithm 1= Original
> >> >>Algorithm 2 = using Array.join() and other optimizations by JMcLean
> >> >>Algo 3:  using single static byteArray (Maurice)
> >> >>
> >> >>These are the results I get for 100,000 iterations:
> >> >>
> >> >>Original: 2.74s
> >> >>V2:  2.5s
> >> >>V3:  1.70s
> >> >>
> >> >>Please can you test on your side as well...
> >> >>
> >> >>Maurice
> >> >>
> >> >>-----Message d'origine-----
> >> >>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >> >>Envoyé : samedi 19 octobre 2013 00:56
> >> >>À : dev@flex.apache.org
> >> >>Objet : RE: UID performance
> >> >>
> >> >>I have used a static ByteArray as suggested: much better.
> >> >>Thanks for the suggestion.
> >> >>
> >> >>
> >> >>-----Message d'origine-----
> >> >>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >> >>Envoyé : samedi 19 octobre 2013 00:49
> >> >>À : dev@flex.apache.org
> >> >>Objet : RE: UID performance
> >> >>
> >> >>Sure, I will do that.
> >> >>
> >> >>I will  also post the source so that you can recompile at your
> >> >>convenience.
> >> >>
> >> >>Maurice
> >> >>
> >> >>
> >> >>-----Message d'origine-----
> >> >>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
> >> >>2013
> >> >>00:13 À : dev@flex.apache.org Objet : Re: UID performance
> >> >>
> >> >>I'm a bit surprised that ByteArray.writeByte is faster but maybe
> >> >>Array.join isn't that fast.  I would also like to see a test of a
> >> >>single static bytearray and resetting it and/or overwriting the old
> >> bytes.
> >> >>
> >> >>Maybe if you put a SWF with various algorithms in your people.a.o
> >> >>folder folks can hit it and make sure we all get the same results and
> >> >>then we'll know which algorithm to check in.
> >> >>
> >> >>Thanks for this idea as well.
> >> >>
> >> >>-Alex
> >> >>
> >> >>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
> >> >>wrote:
> >> >>
> >> >>>Any answer ?
> >> >>>
> >> >>>-----Message d'origine-----
> >> >>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >> >>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org
> >>Objet :
> >> >>>RE: UID performance
> >> >>>
> >> >>>Hi,
> >> >>>
> >> >>>I shouldn't have mixed the two options, because it's confusing.
> >> >>>
> >> >>>Actually, V3 option generates uppercase, exactly as the current UUID,
> >> >>>and it's 2x faster.
> >> >>>So let's forget about V4...
> >> >>>
> >> >>>Here is the code:
> >> >>>
> >> >>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
> >> >>>    private static const DASH:int = 45;  // "-"
> >> >>>
> >> >>>public static function createUID():String
> >> >>>    {
> >> >>>        var ba:ByteArray = new ByteArray();
> >> >>>        var i:int;
> >> >>>        var j:int;
> >> >>>
> >> >>>        for (i = 0; i < 8; i++) {
> >> >>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >> >>>       }
> >> >>>
> >> >>>        for (i = 0; i < 3; i++)
> >> >>>        {
> >> >>>            ba.writeByte(DASH);
> >> >>>            for (j = 0; j < 4; j++)
> >> >>>            {
> >> >>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() *
> >>16));
> >> >>>            }
> >> >>>        }
> >> >>>
> >> >>>        ba.writeByte(DASH);
> >> >>>
> >> >>>        var time:Number = new Date().getTime();
> >> >>>
> >> >>>        var timeString:String = ("0000000" +
> >> >>>time.toString(16).toUpperCase()).substr(-8);
> >> >>>        ba.writeUTFBytes(timeString);
> >> >>>
> >> >>>        for (i = 0; i < 4; i++)
> >> >>>        {
> >> >>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >> >>>        }
> >> >>>
> >> >>>        return ba.toString();
> >> >>>    }
> >> >>>
> >> >>>-----Message d'origine-----
> >> >>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
> >> >>>vendredi
> >> >>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
> >> >>>performance
> >> >>>
> >> >>>Hi,
> >> >>>
> >> >>>> V3: generates the random hex bytes one by one, and writes them to
> >> >>>> the BA
> >> >>>> V4: generates 4 or 8 random bytes in one shot, and writes them to
> >> >>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
> >> >>>Probably best not too fiddle too much with the UID construction.
> >> >>>While I can't think of any major issues it would cause there could be
> >> >>>subtle issues due to seeding of random numbers and the like.
> >> >>>
> >> >>>> I don't know if this is acceptable (are we breaking some code if we
> >> >>>>use lowercase instead of uppercase).
> >> >>>
> >> >>>Again can't think of any issues but probably safer if we kept it
> >> >>>upper case.
> >> >>>
> >> >>>Go ahead and post the code it could be interesting/useful to someone.
> >> >>>
> >> >>>Thanks,
> >> >>>Justin
> >> >>
> >> >
> >>
> >>
>
>

Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
A release SWF should outperform a debug SWF, so that's expected.

On 10/18/13 5:07 PM, "Mark Kessler" <ke...@gmail.com> wrote:

>That newer link gives me faster results... lol
>
>1.71s
>1.54s
>0.903s
>
>
>
>On Fri, Oct 18, 2013 at 7:58 PM, Maurice Amsellem <
>maurice.amsellem@systar.com> wrote:
>
>> I tried already and the results are consistent.
>>
>> Here is the link:
>>
>>
>> 
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_relea
>>se.swf
>>
>> Maurice
>>
>> -----Message d'origine-----
>> De : Alex Harui [mailto:aharui@adobe.com]
>> Envoyé : samedi 19 octobre 2013 01:56
>> À : dev@flex.apache.org
>> Objet : Re: UID performance
>>
>> Actually, I thought of one more test that needs to be run which I don't
>> have time to do right now: Release player with release SWF.  Sometimes
>>you
>> can get very different results on the debugger players.
>>
>> Thanks,
>> -Alex
>>
>> On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
>>
>> >Yup, V3 wins on mac and windows for me.
>> >
>> >Thanks for doing it.
>> >
>> >-Alex
>> >
>> >On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>> >wrote:
>> >
>> >>I have posted FB project with the source s + compiled SWF.
>> >>
>> >>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
>> >>p
>> >>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
>> >>f
>> >>
>> >>Algorithm 1= Original
>> >>Algorithm 2 = using Array.join() and other optimizations by JMcLean
>> >>Algo 3:  using single static byteArray (Maurice)
>> >>
>> >>These are the results I get for 100,000 iterations:
>> >>
>> >>Original: 2.74s
>> >>V2:  2.5s
>> >>V3:  1.70s
>> >>
>> >>Please can you test on your side as well...
>> >>
>> >>Maurice
>> >>
>> >>-----Message d'origine-----
>> >>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>> >>Envoyé : samedi 19 octobre 2013 00:56
>> >>À : dev@flex.apache.org
>> >>Objet : RE: UID performance
>> >>
>> >>I have used a static ByteArray as suggested: much better.
>> >>Thanks for the suggestion.
>> >>
>> >>
>> >>-----Message d'origine-----
>> >>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>> >>Envoyé : samedi 19 octobre 2013 00:49
>> >>À : dev@flex.apache.org
>> >>Objet : RE: UID performance
>> >>
>> >>Sure, I will do that.
>> >>
>> >>I will  also post the source so that you can recompile at your
>> >>convenience.
>> >>
>> >>Maurice
>> >>
>> >>
>> >>-----Message d'origine-----
>> >>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
>> >>2013
>> >>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>> >>
>> >>I'm a bit surprised that ByteArray.writeByte is faster but maybe
>> >>Array.join isn't that fast.  I would also like to see a test of a
>> >>single static bytearray and resetting it and/or overwriting the old
>> bytes.
>> >>
>> >>Maybe if you put a SWF with various algorithms in your people.a.o
>> >>folder folks can hit it and make sure we all get the same results and
>> >>then we'll know which algorithm to check in.
>> >>
>> >>Thanks for this idea as well.
>> >>
>> >>-Alex
>> >>
>> >>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>> >>wrote:
>> >>
>> >>>Any answer ?
>> >>>
>> >>>-----Message d'origine-----
>> >>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>> >>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org
>>Objet :
>> >>>RE: UID performance
>> >>>
>> >>>Hi,
>> >>>
>> >>>I shouldn't have mixed the two options, because it's confusing.
>> >>>
>> >>>Actually, V3 option generates uppercase, exactly as the current UUID,
>> >>>and it's 2x faster.
>> >>>So let's forget about V4...
>> >>>
>> >>>Here is the code:
>> >>>
>> >>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>> >>>    private static const DASH:int = 45;  // "-"
>> >>>
>> >>>public static function createUID():String
>> >>>    {
>> >>>        var ba:ByteArray = new ByteArray();
>> >>>        var i:int;
>> >>>        var j:int;
>> >>>
>> >>>        for (i = 0; i < 8; i++) {
>> >>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>> >>>       }
>> >>>
>> >>>        for (i = 0; i < 3; i++)
>> >>>        {
>> >>>            ba.writeByte(DASH);
>> >>>            for (j = 0; j < 4; j++)
>> >>>            {
>> >>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() *
>>16));
>> >>>            }
>> >>>        }
>> >>>
>> >>>        ba.writeByte(DASH);
>> >>>
>> >>>        var time:Number = new Date().getTime();
>> >>>
>> >>>        var timeString:String = ("0000000" +
>> >>>time.toString(16).toUpperCase()).substr(-8);
>> >>>        ba.writeUTFBytes(timeString);
>> >>>
>> >>>        for (i = 0; i < 4; i++)
>> >>>        {
>> >>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>> >>>        }
>> >>>
>> >>>        return ba.toString();
>> >>>    }
>> >>>
>> >>>-----Message d'origine-----
>> >>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
>> >>>vendredi
>> >>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
>> >>>performance
>> >>>
>> >>>Hi,
>> >>>
>> >>>> V3: generates the random hex bytes one by one, and writes them to
>> >>>> the BA
>> >>>> V4: generates 4 or 8 random bytes in one shot, and writes them to
>> >>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>> >>>Probably best not too fiddle too much with the UID construction.
>> >>>While I can't think of any major issues it would cause there could be
>> >>>subtle issues due to seeding of random numbers and the like.
>> >>>
>> >>>> I don't know if this is acceptable (are we breaking some code if we
>> >>>>use lowercase instead of uppercase).
>> >>>
>> >>>Again can't think of any issues but probably safer if we kept it
>> >>>upper case.
>> >>>
>> >>>Go ahead and post the code it could be interesting/useful to someone.
>> >>>
>> >>>Thanks,
>> >>>Justin
>> >>
>> >
>>
>>


Re: UID performance

Posted by Mark Kessler <ke...@gmail.com>.
That newer link gives me faster results... lol

1.71s
1.54s
0.903s



On Fri, Oct 18, 2013 at 7:58 PM, Maurice Amsellem <
maurice.amsellem@systar.com> wrote:

> I tried already and the results are consistent.
>
> Here is the link:
>
>
> https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_release.swf
>
> Maurice
>
> -----Message d'origine-----
> De : Alex Harui [mailto:aharui@adobe.com]
> Envoyé : samedi 19 octobre 2013 01:56
> À : dev@flex.apache.org
> Objet : Re: UID performance
>
> Actually, I thought of one more test that needs to be run which I don't
> have time to do right now: Release player with release SWF.  Sometimes you
> can get very different results on the debugger players.
>
> Thanks,
> -Alex
>
> On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
>
> >Yup, V3 wins on mac and windows for me.
> >
> >Thanks for doing it.
> >
> >-Alex
> >
> >On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
> >wrote:
> >
> >>I have posted FB project with the source s + compiled SWF.
> >>
> >>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
> >>p
> >>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
> >>f
> >>
> >>Algorithm 1= Original
> >>Algorithm 2 = using Array.join() and other optimizations by JMcLean
> >>Algo 3:  using single static byteArray (Maurice)
> >>
> >>These are the results I get for 100,000 iterations:
> >>
> >>Original: 2.74s
> >>V2:  2.5s
> >>V3:  1.70s
> >>
> >>Please can you test on your side as well...
> >>
> >>Maurice
> >>
> >>-----Message d'origine-----
> >>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >>Envoyé : samedi 19 octobre 2013 00:56
> >>À : dev@flex.apache.org
> >>Objet : RE: UID performance
> >>
> >>I have used a static ByteArray as suggested: much better.
> >>Thanks for the suggestion.
> >>
> >>
> >>-----Message d'origine-----
> >>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >>Envoyé : samedi 19 octobre 2013 00:49
> >>À : dev@flex.apache.org
> >>Objet : RE: UID performance
> >>
> >>Sure, I will do that.
> >>
> >>I will  also post the source so that you can recompile at your
> >>convenience.
> >>
> >>Maurice
> >>
> >>
> >>-----Message d'origine-----
> >>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
> >>2013
> >>00:13 À : dev@flex.apache.org Objet : Re: UID performance
> >>
> >>I'm a bit surprised that ByteArray.writeByte is faster but maybe
> >>Array.join isn't that fast.  I would also like to see a test of a
> >>single static bytearray and resetting it and/or overwriting the old
> bytes.
> >>
> >>Maybe if you put a SWF with various algorithms in your people.a.o
> >>folder folks can hit it and make sure we all get the same results and
> >>then we'll know which algorithm to check in.
> >>
> >>Thanks for this idea as well.
> >>
> >>-Alex
> >>
> >>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
> >>wrote:
> >>
> >>>Any answer ?
> >>>
> >>>-----Message d'origine-----
> >>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
> >>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
> >>>RE: UID performance
> >>>
> >>>Hi,
> >>>
> >>>I shouldn't have mixed the two options, because it's confusing.
> >>>
> >>>Actually, V3 option generates uppercase, exactly as the current UUID,
> >>>and it's 2x faster.
> >>>So let's forget about V4...
> >>>
> >>>Here is the code:
> >>>
> >>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
> >>>    private static const DASH:int = 45;  // "-"
> >>>
> >>>public static function createUID():String
> >>>    {
> >>>        var ba:ByteArray = new ByteArray();
> >>>        var i:int;
> >>>        var j:int;
> >>>
> >>>        for (i = 0; i < 8; i++) {
> >>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >>>       }
> >>>
> >>>        for (i = 0; i < 3; i++)
> >>>        {
> >>>            ba.writeByte(DASH);
> >>>            for (j = 0; j < 4; j++)
> >>>            {
> >>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >>>            }
> >>>        }
> >>>
> >>>        ba.writeByte(DASH);
> >>>
> >>>        var time:Number = new Date().getTime();
> >>>
> >>>        var timeString:String = ("0000000" +
> >>>time.toString(16).toUpperCase()).substr(-8);
> >>>        ba.writeUTFBytes(timeString);
> >>>
> >>>        for (i = 0; i < 4; i++)
> >>>        {
> >>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
> >>>        }
> >>>
> >>>        return ba.toString();
> >>>    }
> >>>
> >>>-----Message d'origine-----
> >>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
> >>>vendredi
> >>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
> >>>performance
> >>>
> >>>Hi,
> >>>
> >>>> V3: generates the random hex bytes one by one, and writes them to
> >>>> the BA
> >>>> V4: generates 4 or 8 random bytes in one shot, and writes them to
> >>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
> >>>Probably best not too fiddle too much with the UID construction.
> >>>While I can't think of any major issues it would cause there could be
> >>>subtle issues due to seeding of random numbers and the like.
> >>>
> >>>> I don't know if this is acceptable (are we breaking some code if we
> >>>>use lowercase instead of uppercase).
> >>>
> >>>Again can't think of any issues but probably safer if we kept it
> >>>upper case.
> >>>
> >>>Go ahead and post the code it could be interesting/useful to someone.
> >>>
> >>>Thanks,
> >>>Justin
> >>
> >
>
>

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Thanks Justin,

I just pushed the new algorithm to develop/branch.

I contains an additional optimization to avoid the TimeString concat and substr, 
so the final algo is around 4x faster on Chrome 11.9 non debug.

Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : dimanche 20 octobre 2013 00:33
À : dev@flex.apache.org
Objet : Re: UID performance

Hi,

OSX Safari 11.8 (debug)

Original: 1.25
V2 with join : 1.00
v3 with bytyearray: 0.625

OSX Chrome 11.9 (non debug)
Original: 0.958
V2: 0.898
V3: 0.374

So I think it fair to say let go with the ByteArray solution. There a few other functions in that same class that could be improved.

Thanks,
Justin


Re: UID performance

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

OSX Safari 11.8 (debug)

Original: 1.25
V2 with join : 1.00
v3 with bytyearray: 0.625

OSX Chrome 11.9 (non debug)
Original: 0.958
V2: 0.898
V3: 0.374

So I think it fair to say let go with the ByteArray solution. There a few other functions in that same class that could be improved.

Thanks,
Justin


Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
Thanks for providing the release SWF.  For me the results are even better:

Win7 Chrome FP11.8 release player

1.39s
1.29s
0.430s

That's better than 2x, more like 3x where in the debugger player it wasn't
quite 2x.

Excellent job!
-Alex

On 10/18/13 4:58 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>I tried already and the results are consistent.
>
>Here is the link:
>
>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_releas
>e.swf
>
>Maurice 
>
>-----Message d'origine-----
>De : Alex Harui [mailto:aharui@adobe.com]
>Envoyé : samedi 19 octobre 2013 01:56
>À : dev@flex.apache.org
>Objet : Re: UID performance
>
>Actually, I thought of one more test that needs to be run which I don't
>have time to do right now: Release player with release SWF.  Sometimes
>you can get very different results on the debugger players.
>
>Thanks,
>-Alex
>
>On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:
>
>>Yup, V3 wins on mac and windows for me.
>>
>>Thanks for doing it.
>>
>>-Alex
>>
>>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>I have posted FB project with the source s + compiled SWF.
>>>
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
>>>p 
>>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
>>>f
>>>
>>>Algorithm 1= Original
>>>Algorithm 2 = using Array.join() and other optimizations by JMcLean
>>>Algo 3:  using single static byteArray (Maurice)
>>>
>>>These are the results I get for 100,000 iterations:
>>>
>>>Original: 2.74s
>>>V2:  2.5s
>>>V3:  1.70s
>>>
>>>Please can you test on your side as well...
>>>
>>>Maurice
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:56
>>>À : dev@flex.apache.org
>>>Objet : RE: UID performance
>>>
>>>I have used a static ByteArray as suggested: much better.
>>>Thanks for the suggestion.
>>>
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : samedi 19 octobre 2013 00:49
>>>À : dev@flex.apache.org
>>>Objet : RE: UID performance
>>>
>>>Sure, I will do that.
>>>
>>>I will  also post the source so that you can recompile at your
>>>convenience.
>>>
>>>Maurice
>>>
>>>
>>>-----Message d'origine-----
>>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre
>>>2013
>>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>>
>>>I'm a bit surprised that ByteArray.writeByte is faster but maybe
>>>Array.join isn't that fast.  I would also like to see a test of a
>>>single static bytearray and resetting it and/or overwriting the old
>>>bytes.
>>>
>>>Maybe if you put a SWF with various algorithms in your people.a.o
>>>folder folks can hit it and make sure we all get the same results and
>>>then we'll know which algorithm to check in.
>>>
>>>Thanks for this idea as well.
>>>
>>>-Alex
>>>
>>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>>wrote:
>>>
>>>>Any answer ? 
>>>>
>>>>-----Message d'origine-----
>>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>>RE: UID performance
>>>>
>>>>Hi,
>>>>
>>>>I shouldn't have mixed the two options, because it's confusing.
>>>>
>>>>Actually, V3 option generates uppercase, exactly as the current UUID,
>>>>and it's 2x faster.
>>>>So let's forget about V4...
>>>>
>>>>Here is the code:
>>>>
>>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>>    private static const DASH:int = 45;  // "-"
>>>>
>>>>public static function createUID():String
>>>>    {
>>>>        var ba:ByteArray = new ByteArray();
>>>>        var i:int;
>>>>        var j:int;
>>>>
>>>>        for (i = 0; i < 8; i++) {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>       }
>>>>
>>>>        for (i = 0; i < 3; i++)
>>>>        {
>>>>            ba.writeByte(DASH);
>>>>            for (j = 0; j < 4; j++)
>>>>            {
>>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>            }
>>>>        }
>>>>
>>>>        ba.writeByte(DASH);
>>>>
>>>>        var time:Number = new Date().getTime();
>>>>
>>>>        var timeString:String = ("0000000" +
>>>>time.toString(16).toUpperCase()).substr(-8);
>>>>        ba.writeUTFBytes(timeString);
>>>>
>>>>        for (i = 0; i < 4; i++)
>>>>        {
>>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>>        }
>>>>
>>>>        return ba.toString();
>>>>    }
>>>>
>>>>-----Message d'origine-----
>>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé :
>>>>vendredi
>>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
>>>>performance
>>>>
>>>>Hi,
>>>>
>>>>> V3: generates the random hex bytes one by one, and writes them to
>>>>> the BA
>>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to
>>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>>>>Probably best not too fiddle too much with the UID construction.
>>>>While I can't think of any major issues it would cause there could be
>>>>subtle issues due to seeding of random numbers and the like.
>>>>
>>>>> I don't know if this is acceptable (are we breaking some code if we
>>>>>use lowercase instead of uppercase).
>>>>
>>>>Again can't think of any issues but probably safer if we kept it
>>>>upper case.
>>>>
>>>>Go ahead and post the code it could be interesting/useful to someone.
>>>>
>>>>Thanks,
>>>>Justin
>>>
>>
>


RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
I tried already and the results are consistent.

Here is the link:

https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf_release.swf

Maurice 

-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] 
Envoyé : samedi 19 octobre 2013 01:56
À : dev@flex.apache.org
Objet : Re: UID performance

Actually, I thought of one more test that needs to be run which I don't have time to do right now: Release player with release SWF.  Sometimes you can get very different results on the debugger players.

Thanks,
-Alex

On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:

>Yup, V3 wins on mac and windows for me.
>
>Thanks for doing it.
>
>-Alex
>
>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>wrote:
>
>>I have posted FB project with the source s + compiled SWF.
>>
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fx
>>p 
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.sw
>>f
>>
>>Algorithm 1= Original
>>Algorithm 2 = using Array.join() and other optimizations by JMcLean 
>>Algo 3:  using single static byteArray (Maurice)
>>
>>These are the results I get for 100,000 iterations:
>>
>>Original: 2.74s
>>V2:  2.5s
>>V3:  1.70s
>>
>>Please can you test on your side as well...
>>
>>Maurice
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : samedi 19 octobre 2013 00:56
>>À : dev@flex.apache.org
>>Objet : RE: UID performance
>>
>>I have used a static ByteArray as suggested: much better.
>>Thanks for the suggestion.
>>
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : samedi 19 octobre 2013 00:49
>>À : dev@flex.apache.org
>>Objet : RE: UID performance
>>
>>Sure, I will do that.
>>
>>I will  also post the source so that you can recompile at your 
>>convenience.
>>
>>Maurice
>>
>>
>>-----Message d'origine-----
>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 
>>2013
>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>
>>I'm a bit surprised that ByteArray.writeByte is faster but maybe 
>>Array.join isn't that fast.  I would also like to see a test of a 
>>single static bytearray and resetting it and/or overwriting the old bytes.
>>
>>Maybe if you put a SWF with various algorithms in your people.a.o 
>>folder folks can hit it and make sure we all get the same results and 
>>then we'll know which algorithm to check in.
>>
>>Thanks for this idea as well.
>>
>>-Alex
>>
>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>Any answer ? 
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>RE: UID performance
>>>
>>>Hi,
>>>
>>>I shouldn't have mixed the two options, because it's confusing.
>>>
>>>Actually, V3 option generates uppercase, exactly as the current UUID, 
>>>and it's 2x faster.
>>>So let's forget about V4...
>>>
>>>Here is the code:
>>>
>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>    private static const DASH:int = 45;  // "-"
>>>
>>>public static function createUID():String
>>>    {
>>>        var ba:ByteArray = new ByteArray();
>>>        var i:int;
>>>        var j:int;
>>>
>>>        for (i = 0; i < 8; i++) {
>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>       }
>>>
>>>        for (i = 0; i < 3; i++)
>>>        {
>>>            ba.writeByte(DASH);
>>>            for (j = 0; j < 4; j++)
>>>            {
>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>            }
>>>        }
>>>
>>>        ba.writeByte(DASH);
>>>
>>>        var time:Number = new Date().getTime();
>>>
>>>        var timeString:String = ("0000000" + 
>>>time.toString(16).toUpperCase()).substr(-8);
>>>        ba.writeUTFBytes(timeString);
>>>
>>>        for (i = 0; i < 4; i++)
>>>        {
>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>        }
>>>
>>>        return ba.toString();
>>>    }
>>>
>>>-----Message d'origine-----
>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : 
>>>vendredi
>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>>>performance
>>>
>>>Hi,
>>>
>>>> V3: generates the random hex bytes one by one, and writes them to 
>>>> the BA
>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to 
>>>> the BA  (hexa in lowercase, to avoid call toUppercase() )
>>>Probably best not too fiddle too much with the UID construction. 
>>>While I can't think of any major issues it would cause there could be 
>>>subtle issues due to seeding of random numbers and the like.
>>>
>>>> I don't know if this is acceptable (are we breaking some code if we 
>>>>use lowercase instead of uppercase).
>>>
>>>Again can't think of any issues but probably safer if we kept it 
>>>upper case.
>>>
>>>Go ahead and post the code it could be interesting/useful to someone.
>>>
>>>Thanks,
>>>Justin
>>
>


Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
Actually, I thought of one more test that needs to be run which I don't
have time to do right now: Release player with release SWF.  Sometimes you
can get very different results on the debugger players.

Thanks,
-Alex

On 10/18/13 4:53 PM, "Alex Harui" <ah...@adobe.com> wrote:

>Yup, V3 wins on mac and windows for me.
>
>Thanks for doing it.
>
>-Alex
>
>On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
>wrote:
>
>>I have posted FB project with the source s + compiled SWF.
>>
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fxp
>>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.swf
>>
>>Algorithm 1= Original
>>Algorithm 2 = using Array.join() and other optimizations by JMcLean
>>Algo 3:  using single static byteArray (Maurice)
>>
>>These are the results I get for 100,000 iterations:
>>
>>Original: 2.74s
>>V2:  2.5s
>>V3:  1.70s
>>
>>Please can you test on your side as well...
>>
>>Maurice 
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : samedi 19 octobre 2013 00:56
>>À : dev@flex.apache.org
>>Objet : RE: UID performance
>>
>>I have used a static ByteArray as suggested: much better.
>>Thanks for the suggestion.
>>
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : samedi 19 octobre 2013 00:49
>>À : dev@flex.apache.org
>>Objet : RE: UID performance
>>
>>Sure, I will do that.
>>
>>I will  also post the source so that you can recompile at your
>>convenience.
>>
>>Maurice 
>>
>>
>>-----Message d'origine-----
>>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013
>>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>>
>>I'm a bit surprised that ByteArray.writeByte is faster but maybe
>>Array.join isn't that fast.  I would also like to see a test of a single
>>static bytearray and resetting it and/or overwriting the old bytes.
>>
>>Maybe if you put a SWF with various algorithms in your people.a.o folder
>>folks can hit it and make sure we all get the same results and then we'll
>>know which algorithm to check in.
>>
>>Thanks for this idea as well.
>>
>>-Alex
>>
>>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>>wrote:
>>
>>>Any answer ? 
>>>
>>>-----Message d'origine-----
>>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>>RE: UID performance
>>>
>>>Hi,
>>>
>>>I shouldn't have mixed the two options, because it's confusing.
>>>
>>>Actually, V3 option generates uppercase, exactly as the current UUID,
>>>and it's 2x faster.
>>>So let's forget about V4...
>>>
>>>Here is the code:
>>>
>>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>>    private static const DASH:int = 45;  // "-"
>>>
>>>public static function createUID():String
>>>    {
>>>        var ba:ByteArray = new ByteArray();
>>>        var i:int;
>>>        var j:int;
>>>
>>>        for (i = 0; i < 8; i++) {
>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>       }
>>>
>>>        for (i = 0; i < 3; i++)
>>>        {
>>>            ba.writeByte(DASH);
>>>            for (j = 0; j < 4; j++)
>>>            {
>>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>            }
>>>        }
>>>
>>>        ba.writeByte(DASH);
>>>
>>>        var time:Number = new Date().getTime();
>>>
>>>        var timeString:String = ("0000000" +
>>>time.toString(16).toUpperCase()).substr(-8);
>>>        ba.writeUTFBytes(timeString);
>>>
>>>        for (i = 0; i < 4; i++)
>>>        {
>>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>>        }
>>>
>>>        return ba.toString();
>>>    }
>>>
>>>-----Message d'origine-----
>>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi
>>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
>>>performance
>>>
>>>Hi,
>>>
>>>> V3: generates the random hex bytes one by one, and writes them to the
>>>> BA
>>>> V4: generates 4 or 8 random bytes in one shot, and writes them to the
>>>> BA  (hexa in lowercase, to avoid call toUppercase() )
>>>Probably best not too fiddle too much with the UID construction. While
>>>I can't think of any major issues it would cause there could be subtle
>>>issues due to seeding of random numbers and the like.
>>>
>>>> I don't know if this is acceptable (are we breaking some code if we
>>>>use lowercase instead of uppercase).
>>>
>>>Again can't think of any issues but probably safer if we kept it upper
>>>case.
>>>
>>>Go ahead and post the code it could be interesting/useful to someone.
>>>
>>>Thanks,
>>>Justin
>>
>


Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
Yup, V3 wins on mac and windows for me.

Thanks for doing it.

-Alex

On 10/18/13 4:45 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>I have posted FB project with the source s + compiled SWF.
>
>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fxp
>https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.swf
>
>Algorithm 1= Original
>Algorithm 2 = using Array.join() and other optimizations by JMcLean
>Algo 3:  using single static byteArray (Maurice)
>
>These are the results I get for 100,000 iterations:
>
>Original: 2.74s
>V2:  2.5s
>V3:  1.70s
>
>Please can you test on your side as well...
>
>Maurice 
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : samedi 19 octobre 2013 00:56
>À : dev@flex.apache.org
>Objet : RE: UID performance
>
>I have used a static ByteArray as suggested: much better.
>Thanks for the suggestion.
>
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : samedi 19 octobre 2013 00:49
>À : dev@flex.apache.org
>Objet : RE: UID performance
>
>Sure, I will do that.
>
>I will  also post the source so that you can recompile at your
>convenience.
>
>Maurice 
>
>
>-----Message d'origine-----
>De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013
>00:13 À : dev@flex.apache.org Objet : Re: UID performance
>
>I'm a bit surprised that ByteArray.writeByte is faster but maybe
>Array.join isn't that fast.  I would also like to see a test of a single
>static bytearray and resetting it and/or overwriting the old bytes.
>
>Maybe if you put a SWF with various algorithms in your people.a.o folder
>folks can hit it and make sure we all get the same results and then we'll
>know which algorithm to check in.
>
>Thanks for this idea as well.
>
>-Alex
>
>On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
>wrote:
>
>>Any answer ? 
>>
>>-----Message d'origine-----
>>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet :
>>RE: UID performance
>>
>>Hi,
>>
>>I shouldn't have mixed the two options, because it's confusing.
>>
>>Actually, V3 option generates uppercase, exactly as the current UUID,
>>and it's 2x faster.
>>So let's forget about V4...
>>
>>Here is the code:
>>
>>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>>    private static const DASH:int = 45;  // "-"
>>
>>public static function createUID():String
>>    {
>>        var ba:ByteArray = new ByteArray();
>>        var i:int;
>>        var j:int;
>>
>>        for (i = 0; i < 8; i++) {
>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>       }
>>
>>        for (i = 0; i < 3; i++)
>>        {
>>            ba.writeByte(DASH);
>>            for (j = 0; j < 4; j++)
>>            {
>>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>            }
>>        }
>>
>>        ba.writeByte(DASH);
>>
>>        var time:Number = new Date().getTime();
>>
>>        var timeString:String = ("0000000" +
>>time.toString(16).toUpperCase()).substr(-8);
>>        ba.writeUTFBytes(timeString);
>>
>>        for (i = 0; i < 4; i++)
>>        {
>>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>>        }
>>
>>        return ba.toString();
>>    }
>>
>>-----Message d'origine-----
>>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi
>>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID
>>performance
>>
>>Hi,
>>
>>> V3: generates the random hex bytes one by one, and writes them to the
>>> BA
>>> V4: generates 4 or 8 random bytes in one shot, and writes them to the
>>> BA  (hexa in lowercase, to avoid call toUppercase() )
>>Probably best not too fiddle too much with the UID construction. While
>>I can't think of any major issues it would cause there could be subtle
>>issues due to seeding of random numbers and the like.
>>
>>> I don't know if this is acceptable (are we breaking some code if we
>>>use lowercase instead of uppercase).
>>
>>Again can't think of any issues but probably safer if we kept it upper
>>case.
>>
>>Go ahead and post the code it could be interesting/useful to someone.
>>
>>Thanks,
>>Justin
>


RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
I have posted FB project with the source s + compiled SWF.

https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.fxp
https://dl.dropboxusercontent.com/u/12169005/ApacheFlex/TestUIDPerf.swf

Algorithm 1= Original 
Algorithm 2 = using Array.join() and other optimizations by JMcLean
Algo 3:  using single static byteArray (Maurice)

These are the results I get for 100,000 iterations:

Original: 2.74s
V2:  2.5s
V3:  1.70s

Please can you test on your side as well...

Maurice 

-----Message d'origine-----
De : Maurice Amsellem [mailto:maurice.amsellem@systar.com] 
Envoyé : samedi 19 octobre 2013 00:56
À : dev@flex.apache.org
Objet : RE: UID performance

I have used a static ByteArray as suggested: much better.
Thanks for the suggestion.


-----Message d'origine-----
De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
Envoyé : samedi 19 octobre 2013 00:49
À : dev@flex.apache.org
Objet : RE: UID performance

Sure, I will do that.

I will  also post the source so that you can recompile at your convenience.

Maurice 


-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013 00:13 À : dev@flex.apache.org Objet : Re: UID performance

I'm a bit surprised that ByteArray.writeByte is faster but maybe Array.join isn't that fast.  I would also like to see a test of a single static bytearray and resetting it and/or overwriting the old bytes.

Maybe if you put a SWF with various algorithms in your people.a.o folder folks can hit it and make sure we all get the same results and then we'll know which algorithm to check in.

Thanks for this idea as well.

-Alex

On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>Any answer ? 
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet : 
>RE: UID performance
>
>Hi,
>
>I shouldn't have mixed the two options, because it's confusing.
>
>Actually, V3 option generates uppercase, exactly as the current UUID, 
>and it's 2x faster.
>So let's forget about V4...
>
>Here is the code:
>
>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>    private static const DASH:int = 45;  // "-"
>
>public static function createUID():String
>    {
>        var ba:ByteArray = new ByteArray();
>        var i:int;
>        var j:int;
>
>        for (i = 0; i < 8; i++) {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>       }
>
>        for (i = 0; i < 3; i++)
>        {
>            ba.writeByte(DASH);
>            for (j = 0; j < 4; j++)
>            {
>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>            }
>        }
>
>        ba.writeByte(DASH);
>
>        var time:Number = new Date().getTime();
>
>        var timeString:String = ("0000000" + 
>time.toString(16).toUpperCase()).substr(-8);
>        ba.writeUTFBytes(timeString);
>
>        for (i = 0; i < 4; i++)
>        {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>        }
>
>        return ba.toString();
>    }
>
>-----Message d'origine-----
>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi
>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>performance
>
>Hi,
>
>> V3: generates the random hex bytes one by one, and writes them to the 
>> BA
>> V4: generates 4 or 8 random bytes in one shot, and writes them to the 
>> BA  (hexa in lowercase, to avoid call toUppercase() )
>Probably best not too fiddle too much with the UID construction. While 
>I can't think of any major issues it would cause there could be subtle 
>issues due to seeding of random numbers and the like.
>
>> I don't know if this is acceptable (are we breaking some code if we 
>>use lowercase instead of uppercase).
>
>Again can't think of any issues but probably safer if we kept it upper 
>case.
>
>Go ahead and post the code it could be interesting/useful to someone.
>
>Thanks,
>Justin


RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
I have used a static ByteArray as suggested: much better.
Thanks for the suggestion.


-----Message d'origine-----
De : Maurice Amsellem [mailto:maurice.amsellem@systar.com] 
Envoyé : samedi 19 octobre 2013 00:49
À : dev@flex.apache.org
Objet : RE: UID performance

Sure, I will do that.

I will  also post the source so that you can recompile at your convenience.

Maurice 


-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] Envoyé : samedi 19 octobre 2013 00:13 À : dev@flex.apache.org Objet : Re: UID performance

I'm a bit surprised that ByteArray.writeByte is faster but maybe Array.join isn't that fast.  I would also like to see a test of a single static bytearray and resetting it and/or overwriting the old bytes.

Maybe if you put a SWF with various algorithms in your people.a.o folder folks can hit it and make sure we all get the same results and then we'll know which algorithm to check in.

Thanks for this idea as well.

-Alex

On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>Any answer ? 
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet : 
>RE: UID performance
>
>Hi,
>
>I shouldn't have mixed the two options, because it's confusing.
>
>Actually, V3 option generates uppercase, exactly as the current UUID, 
>and it's 2x faster.
>So let's forget about V4...
>
>Here is the code:
>
>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>    private static const DASH:int = 45;  // "-"
>
>public static function createUID():String
>    {
>        var ba:ByteArray = new ByteArray();
>        var i:int;
>        var j:int;
>
>        for (i = 0; i < 8; i++) {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>       }
>
>        for (i = 0; i < 3; i++)
>        {
>            ba.writeByte(DASH);
>            for (j = 0; j < 4; j++)
>            {
>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>            }
>        }
>
>        ba.writeByte(DASH);
>
>        var time:Number = new Date().getTime();
>
>        var timeString:String = ("0000000" + 
>time.toString(16).toUpperCase()).substr(-8);
>        ba.writeUTFBytes(timeString);
>
>        for (i = 0; i < 4; i++)
>        {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>        }
>
>        return ba.toString();
>    }
>
>-----Message d'origine-----
>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi
>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>performance
>
>Hi,
>
>> V3: generates the random hex bytes one by one, and writes them to the 
>> BA
>> V4: generates 4 or 8 random bytes in one shot, and writes them to the 
>> BA  (hexa in lowercase, to avoid call toUppercase() )
>Probably best not too fiddle too much with the UID construction. While 
>I can't think of any major issues it would cause there could be subtle 
>issues due to seeding of random numbers and the like.
>
>> I don't know if this is acceptable (are we breaking some code if we 
>>use lowercase instead of uppercase).
>
>Again can't think of any issues but probably safer if we kept it upper 
>case.
>
>Go ahead and post the code it could be interesting/useful to someone.
>
>Thanks,
>Justin


RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Sure, I will do that.

I will  also post the source so that you can recompile at your convenience.

Maurice 


-----Message d'origine-----
De : Alex Harui [mailto:aharui@adobe.com] 
Envoyé : samedi 19 octobre 2013 00:13
À : dev@flex.apache.org
Objet : Re: UID performance

I'm a bit surprised that ByteArray.writeByte is faster but maybe Array.join isn't that fast.  I would also like to see a test of a single static bytearray and resetting it and/or overwriting the old bytes.

Maybe if you put a SWF with various algorithms in your people.a.o folder folks can hit it and make sure we all get the same results and then we'll know which algorithm to check in.

Thanks for this idea as well.

-Alex

On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>Any answer ? 
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : vendredi 18 octobre 2013 14:39 À : dev@flex.apache.org Objet : 
>RE: UID performance
>
>Hi,
>
>I shouldn't have mixed the two options, because it's confusing.
>
>Actually, V3 option generates uppercase, exactly as the current UUID, 
>and it's 2x faster.
>So let's forget about V4...
>
>Here is the code:
>
>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>    private static const DASH:int = 45;  // "-"
>
>public static function createUID():String
>    {
>        var ba:ByteArray = new ByteArray();
>        var i:int;
>        var j:int;
>
>        for (i = 0; i < 8; i++) {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>       }
>
>        for (i = 0; i < 3; i++)
>        {
>            ba.writeByte(DASH);
>            for (j = 0; j < 4; j++)
>            {
>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>            }
>        }
>
>        ba.writeByte(DASH);
>
>        var time:Number = new Date().getTime();
>
>        var timeString:String = ("0000000" + 
>time.toString(16).toUpperCase()).substr(-8);
>        ba.writeUTFBytes(timeString);
>
>        for (i = 0; i < 4; i++)
>        {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>        }
>
>        return ba.toString();
>    }
>
>-----Message d'origine-----
>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi 
>18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID 
>performance
>
>Hi,
>
>> V3: generates the random hex bytes one by one, and writes them to the 
>> BA
>> V4: generates 4 or 8 random bytes in one shot, and writes them to the 
>> BA  (hexa in lowercase, to avoid call toUppercase() )
>Probably best not too fiddle too much with the UID construction. While 
>I can't think of any major issues it would cause there could be subtle 
>issues due to seeding of random numbers and the like.
>
>> I don't know if this is acceptable (are we breaking some code if we 
>>use lowercase instead of uppercase).
>
>Again can't think of any issues but probably safer if we kept it upper 
>case.
>
>Go ahead and post the code it could be interesting/useful to someone.
>
>Thanks,
>Justin


Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
I'm a bit surprised that ByteArray.writeByte is faster but maybe
Array.join isn't that fast.  I would also like to see a test of a single
static bytearray and resetting it and/or overwriting the old bytes.

Maybe if you put a SWF with various algorithms in your people.a.o folder
folks can hit it and make sure we all get the same results and then we'll
know which algorithm to check in.

Thanks for this idea as well.

-Alex

On 10/18/13 3:05 PM, "Maurice Amsellem" <ma...@systar.com>
wrote:

>Any answer ? 
>
>-----Message d'origine-----
>De : Maurice Amsellem [mailto:maurice.amsellem@systar.com]
>Envoyé : vendredi 18 octobre 2013 14:39
>À : dev@flex.apache.org
>Objet : RE: UID performance
>
>Hi,
>
>I shouldn't have mixed the two options, because it's confusing.
>
>Actually, V3 option generates uppercase, exactly as the current UUID, and
>it's 2x faster.
>So let's forget about V4...
>
>Here is the code:
>
>    private static const HEX_CHARS:String = "0123456789ABCDEF";
>    private static const DASH:int = 45;  // "-"
>
>public static function createUID():String
>    {
>        var ba:ByteArray = new ByteArray();
>        var i:int;
>        var j:int;
>
>        for (i = 0; i < 8; i++) {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>       }
>
>        for (i = 0; i < 3; i++)
>        {
>            ba.writeByte(DASH);
>            for (j = 0; j < 4; j++)
>            {
>                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>            }
>        }
>
>        ba.writeByte(DASH);
>
>        var time:Number = new Date().getTime();
>
>        var timeString:String = ("0000000" +
>time.toString(16).toUpperCase()).substr(-8);
>        ba.writeUTFBytes(timeString);
>
>        for (i = 0; i < 4; i++)
>        {
>            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
>        }
>
>        return ba.toString();
>    }
>
>-----Message d'origine-----
>De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi 18
>octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID performance
>
>Hi,
>
>> V3: generates the random hex bytes one by one, and writes them to the
>> BA
>> V4: generates 4 or 8 random bytes in one shot, and writes them to the
>> BA  (hexa in lowercase, to avoid call toUppercase() )
>Probably best not too fiddle too much with the UID construction. While I
>can't think of any major issues it would cause there could be subtle
>issues due to seeding of random numbers and the like.
>
>> I don't know if this is acceptable (are we breaking some code if we use
>>lowercase instead of uppercase).
>
>Again can't think of any issues but probably safer if we kept it upper
>case.
>
>Go ahead and post the code it could be interesting/useful to someone.
>
>Thanks,
>Justin


RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Any answer ? 

-----Message d'origine-----
De : Maurice Amsellem [mailto:maurice.amsellem@systar.com] 
Envoyé : vendredi 18 octobre 2013 14:39
À : dev@flex.apache.org
Objet : RE: UID performance

Hi,

I shouldn't have mixed the two options, because it's confusing.

Actually, V3 option generates uppercase, exactly as the current UUID, and it's 2x faster.
So let's forget about V4...

Here is the code:

    private static const HEX_CHARS:String = "0123456789ABCDEF";
    private static const DASH:int = 45;  // "-"

public static function createUID():String
    {
        var ba:ByteArray = new ByteArray();
        var i:int;
        var j:int;

        for (i = 0; i < 8; i++) {
            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
       }

        for (i = 0; i < 3; i++)
        {
            ba.writeByte(DASH);
            for (j = 0; j < 4; j++)
            {
                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
            }
        }

        ba.writeByte(DASH);

        var time:Number = new Date().getTime();

        var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
        ba.writeUTFBytes(timeString);

        for (i = 0; i < 4; i++)
        {
            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
        }

        return ba.toString();
    }

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] Envoyé : vendredi 18 octobre 2013 14:34 À : dev@flex.apache.org Objet : Re: UID performance

Hi,

> V3: generates the random hex bytes one by one, and writes them to the 
> BA
> V4: generates 4 or 8 random bytes in one shot, and writes them to the 
> BA  (hexa in lowercase, to avoid call toUppercase() )
Probably best not too fiddle too much with the UID construction. While I can't think of any major issues it would cause there could be subtle issues due to seeding of random numbers and the like. 

> I don't know if this is acceptable (are we breaking some code if we use lowercase instead of uppercase).

Again can't think of any issues but probably safer if we kept it upper case.

Go ahead and post the code it could be interesting/useful to someone.

Thanks,
Justin

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Hi,

I shouldn't have mixed the two options, because it's confusing.

Actually, V3 option generates uppercase, exactly as the current UUID, and it's 2x faster.
So let's forget about V4...

Here is the code:

    private static const HEX_CHARS:String = "0123456789ABCDEF";
    private static const DASH:int = 45;  // "-"

public static function createUID():String
    {
        var ba:ByteArray = new ByteArray();
        var i:int;
        var j:int;

        for (i = 0; i < 8; i++) {
            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
       }

        for (i = 0; i < 3; i++)
        {
            ba.writeByte(DASH);
            for (j = 0; j < 4; j++)
            {
                ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
            }
        }

        ba.writeByte(DASH);

        var time:Number = new Date().getTime();

        var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
        ba.writeUTFBytes(timeString);

        for (i = 0; i < 4; i++)
        {
            ba.writeByte(HEX_CHARS.charCodeAt(Math.random() * 16));
        }

        return ba.toString();
    }

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : vendredi 18 octobre 2013 14:34
À : dev@flex.apache.org
Objet : Re: UID performance

Hi,

> V3: generates the random hex bytes one by one, and writes them to the BA
> V4: generates 4 or 8 random bytes in one shot, and writes them to the BA  (hexa in lowercase, to avoid call toUppercase() )
Probably best not too fiddle too much with the UID construction. While I can't think of any major issues it would cause there could be subtle issues due to seeding of random numbers and the like. 

> I don't know if this is acceptable (are we breaking some code if we use lowercase instead of uppercase).

Again can't think of any issues but probably safer if we kept it upper case.

Go ahead and post the code it could be interesting/useful to someone.

Thanks,
Justin

Re: UID performance

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> V3: generates the random hex bytes one by one, and writes them to the BA
> V4: generates 4 or 8 random bytes in one shot, and writes them to the BA  (hexa in lowercase, to avoid call toUppercase() )
Probably best not too fiddle too much with the UID construction. While I can't think of any major issues it would cause there could be subtle issues due to seeding of random numbers and the like. 

> I don't know if this is acceptable (are we breaking some code if we use lowercase instead of uppercase).

Again can't think of any issues but probably safer if we kept it upper case.

Go ahead and post the code it could be interesting/useful to someone.

Thanks,
Justin

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Hi ,  I have tried out of curiosity other optimizations, such as using ByteArray to generate the string.

I have two variants:
V3: generates the random hex bytes one by one, and writes them to the BA
V4: generates 4 or 8 random bytes in one shot, and writes them to the BA  (hexa in lowercase, to avoid call toUppercase() )

The results are the following : (200,000x , debug = true) 

Original:	4.48s 
JMcLean:	3.905s 
V3:		2.972s 
V4 : 		2.404s 

Remark:  V4 is the fastest, but it generates an UID with lower case abcdef instead of ABCDEF.
I don't know if this is acceptable (are we breaking some code if we use lowercase instead of uppercase).

If you want, I can post the code for the two variants...

Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : vendredi 18 octobre 2013 11:17
À : dev@flex.apache.org
Objet : Re: UID performance

Hi,

See http://gaming.adobe.com/technologies/scout/

"For a limited time, you can get Scout as part of a free Creative Cloud membership."

Get it while you can :-)

Justin

Re: UID performance

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

See http://gaming.adobe.com/technologies/scout/

"For a limited time, you can get Scout as part of a free Creative Cloud membership."

Get it while you can :-)

Justin

AW: UID performance

Posted by "christofer.dutz@c-ware.de" <ch...@c-ware.de>.
It's allways free? ... ok then this doesn't suck at all ;-) 
At least it explains why I coulnd't find a package in which I could purchase it.

________________________________________
Von: Justin Mclean [justin@classsoftware.com]
Gesendet: Freitag, 18. Oktober 2013 11:08
An: dev@flex.apache.org
Betreff: Re: UID performance

Hi,

> I don't have Scout :-(
Scout is currently free with the free Creative Cloud account last time I checked.

Thanks,
Justin

Re: UID performance

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> I don't have Scout :-(
Scout is currently free with the free Creative Cloud account last time I checked.

Thanks,
Justin

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
I don't have Scout :-(

I have a premium FlashBuilder 4.7 licence.

Does it come with it, or is it a separate purchase?

Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : vendredi 18 octobre 2013 10:08
À : dev@flex.apache.org
Objet : Re: UID performance

Hi,

Well 10% or so is better than nothing.

Mind running though scout may be that getTime is more expensive on windows and skewing the results a little? I vaguely recall something about that in the past.

I tested on OSX.

Thanks,
Justin

Re: UID performance

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

Well 10% or so is better than nothing.

Mind running though scout may be that getTime is more expensive on windows and skewing the results a little? I vaguely recall something about that in the past.

I tested on OSX.

Thanks,
Justin

RE: UID performance

Posted by Maurice Amsellem <ma...@systar.com>.
Hi, I have created simple test suite (in FlexUnit) with  original and new method functions,
 calling 100K times createUID and the results are different for me:

-debug=true:
Old createUID : 2.652s
New createUID: 2.382s

-debug=false, optimize=true
Old createUID : 2.11s
New createUID: 1.878s

Config:  Windows 7, coreI7 , FP 11.8

Any one confirm ?

Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : vendredi 18 octobre 2013 03:18
À : dev@flex.apache.org
Objet : UID performance

Hi,

This is about 2/3rds to twice as fast by my measurements (in Scout). Any one confirm?

Changes include.
- Use a string to store hex digits and charAt rather than array of ascii
- Use Array.join rather than String.fromCharCode
- Remove Math.floor as they are not required
- Set up static array and reuse that rather than creating new array each time

The timeString could probably be improved to remove the string manipulation but put the digits directly into the correct place into the array to save another 5% or so.

BYW any see where Number.toString is being called in there?

Any feedback?

Thanks,
Justin

diff --git a/frameworks/projects/framework/src/mx/utils/UIDUtil.as b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
index 4993563..576b598 100644
--- a/frameworks/projects/framework/src/mx/utils/UIDUtil.as
+++ b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
@@ -61,10 +61,16 @@ public class UIDUtil
 
     /**
      *  @private
-     *  Char codes for 0123456789ABCDEF
      */
-    private static const ALPHA_CHAR_CODES:Array = [48, 49, 50, 51, 52, 53, 54, 
-        55, 56, 57, 65, 66, 67, 68, 69, 70];
+	private static const CHAR_CODES:String = "0123456789ABCDEF";
+	
+	private static var EMPTYUID:Array = [
+		'0','0','0','0','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'0','0','0','0','0','0','0','0','0','0','0','0'
+	];
 
     //--------------------------------------------------------------------------
     //
@@ -106,53 +112,53 @@ public class UIDUtil
      *  @playerversion AIR 1.1
      *  @productversion Flex 3
      */
-    public static function createUID():String
-    {
-        var uid:Array = new Array(36);
-        var index:int = 0;
-        
-        var i:int;
-        var j:int;
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-
-        for (i = 0; i < 3; i++)
-        {
-            uid[index++] = 45; // charCode for "-"
-            
-            for (j = 0; j < 4; j++)
-            {
-                uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-            }
-        }
-        
-        uid[index++] = 45; // charCode for "-"
-
-        var time:Number = new Date().getTime();
-        // Note: time is the number of milliseconds since 1970,
-        // which is currently more than one trillion.
-        // We use the low 8 hex digits of this number in the UID.
-        // Just in case the system clock has been reset to
-        // Jan 1-4, 1970 (in which case this number could have only
-        // 1-7 hex digits), we pad on the left with 7 zeros
-        // before taking the low digits.
-        var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = timeString.charCodeAt(i);
-        }
-        
-        for (i = 0; i < 4; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-        
-        return String.fromCharCode.apply(null, uid);
-    }
+	public static function createUID():String
+	{
+		var uid:Array = EMPTYUID;
+		var index:int = 0;
+		
+		var i:int;
+		var j:int;
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+		}
+		
+		for (i = 0; i < 3; i++)
+		{
+			index++; // skip "-"
+			
+			for (j = 0; j < 4; j++)
+			{
+				uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+			}
+		}
+		
+		index++; // skip "-"
+		
+		var time:Number = new Date().getTime();
+		// Note: time is the number of milliseconds since 1970,
+		// which is currently more than one trillion.
+		// We use the low 8 hex digits of this number in the UID.
+		// Just in case the system clock has been reset to
+		// Jan 1-4, 1970 (in which case this number could have only
+		// 1-7 hex digits), we pad on the left with 7 zeros
+		// before taking the low digits.
+		var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = timeString.charAt(i);
+		}
+		
+		for (i = 0; i < 4; i++)
+		{
+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
+		}
+		
+		return uid.join("");
+	}



Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
Probably implicitly in the array indexing.  I think the index values may
get converted to strings before the array lookup.

On 10/17/13 8:56 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

>Hi,
>
>> Seems reasonable.  Good idea to try join().  Why the question about
>> Number.toString()?
>
>Scout showed it being called but cant see where it's doing number to
>string conversion in that code.
>
>Thanks,
>Justin


Re: UID performance

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> Seems reasonable.  Good idea to try join().  Why the question about
> Number.toString()?

Scout showed it being called but cant see where it's doing number to string conversion in that code.

Thanks,
Justin

Re: UID performance

Posted by Alex Harui <ah...@adobe.com>.
Seems reasonable.  Good idea to try join().  Why the question about
Number.toString()?

-Alex

On 10/17/13 6:17 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

>Hi,
>
>This is about 2/3rds to twice as fast by my measurements (in Scout). Any
>one confirm?
>
>Changes include.
>- Use a string to store hex digits and charAt rather than array of ascii
>- Use Array.join rather than String.fromCharCode
>- Remove Math.floor as they are not required
>- Set up static array and reuse that rather than creating new array each
>time
>
>The timeString could probably be improved to remove the string
>manipulation but put the digits directly into the correct place into the
>array to save another 5% or so.
>
>BYW any see where Number.toString is being called in there?
>
>Any feedback?
>
>Thanks,
>Justin
>
>diff --git a/frameworks/projects/framework/src/mx/utils/UIDUtil.as
>b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
>index 4993563..576b598 100644
>--- a/frameworks/projects/framework/src/mx/utils/UIDUtil.as
>+++ b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
>@@ -61,10 +61,16 @@ public class UIDUtil
> 
>     /**
>      *  @private
>-     *  Char codes for 0123456789ABCDEF
>      */
>-    private static const ALPHA_CHAR_CODES:Array = [48, 49, 50, 51, 52,
>53, 54, 
>-        55, 56, 57, 65, 66, 67, 68, 69, 70];
>+	private static const CHAR_CODES:String = "0123456789ABCDEF";
>+	
>+	private static var EMPTYUID:Array = [
>+		'0','0','0','0','0','0','0','0',
>+		'-','0','0','0','0',
>+		'-','0','0','0','0',
>+		'-','0','0','0','0',
>+		'0','0','0','0','0','0','0','0','0','0','0','0'
>+	];
> 
>     
>//------------------------------------------------------------------------
>--
>     //
>@@ -106,53 +112,53 @@ public class UIDUtil
>      *  @playerversion AIR 1.1
>      *  @productversion Flex 3
>      */
>-    public static function createUID():String
>-    {
>-        var uid:Array = new Array(36);
>-        var index:int = 0;
>-        
>-        var i:int;
>-        var j:int;
>-        
>-        for (i = 0; i < 8; i++)
>-        {
>-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *
>16)];
>-        }
>-
>-        for (i = 0; i < 3; i++)
>-        {
>-            uid[index++] = 45; // charCode for "-"
>-            
>-            for (j = 0; j < 4; j++)
>-            {
>-                uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random()
>*  16)];
>-            }
>-        }
>-        
>-        uid[index++] = 45; // charCode for "-"
>-
>-        var time:Number = new Date().getTime();
>-        // Note: time is the number of milliseconds since 1970,
>-        // which is currently more than one trillion.
>-        // We use the low 8 hex digits of this number in the UID.
>-        // Just in case the system clock has been reset to
>-        // Jan 1-4, 1970 (in which case this number could have only
>-        // 1-7 hex digits), we pad on the left with 7 zeros
>-        // before taking the low digits.
>-        var timeString:String = ("0000000" +
>time.toString(16).toUpperCase()).substr(-8);
>-        
>-        for (i = 0; i < 8; i++)
>-        {
>-            uid[index++] = timeString.charCodeAt(i);
>-        }
>-        
>-        for (i = 0; i < 4; i++)
>-        {
>-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *
>16)];
>-        }
>-        
>-        return String.fromCharCode.apply(null, uid);
>-    }
>+	public static function createUID():String
>+	{
>+		var uid:Array = EMPTYUID;
>+		var index:int = 0;
>+		
>+		var i:int;
>+		var j:int;
>+		
>+		for (i = 0; i < 8; i++)
>+		{
>+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
>+		}
>+		
>+		for (i = 0; i < 3; i++)
>+		{
>+			index++; // skip "-"
>+			
>+			for (j = 0; j < 4; j++)
>+			{
>+				uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
>+			}
>+		}
>+		
>+		index++; // skip "-"
>+		
>+		var time:Number = new Date().getTime();
>+		// Note: time is the number of milliseconds since 1970,
>+		// which is currently more than one trillion.
>+		// We use the low 8 hex digits of this number in the UID.
>+		// Just in case the system clock has been reset to
>+		// Jan 1-4, 1970 (in which case this number could have only
>+		// 1-7 hex digits), we pad on the left with 7 zeros
>+		// before taking the low digits.
>+		var timeString:String = ("0000000" +
>time.toString(16).toUpperCase()).substr(-8);
>+		
>+		for (i = 0; i < 8; i++)
>+		{
>+			uid[index++] = timeString.charAt(i);
>+		}
>+		
>+		for (i = 0; i < 4; i++)
>+		{
>+			uid[index++] = CHAR_CODES.charAt(Math.random() * 16);
>+		}
>+		
>+		return uid.join("");
>+	}
>
>