Coder Social home page Coder Social logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024

Original comment by mikechambers on 2 Jul 2008 at 4:46

  • Changed state: Accepted
  • Added labels: HasAPatch

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
>Change createBlocks to use array reference instead of s.getCharCodeAt()


Can you explain this change?

Also, have you done any performance test on hashing strings between the existing
implementation, and yours?

Original comment by mikechambers on 2 Jul 2008 at 10:30

  • Changed state: NeedMoreInfo

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
Hi Mike,

>Change createBlocks to use array reference instead of s.getCharCodeAt()
As the createBlocks now takes a byteArray instead of a string, I'm using direct 
array
notation to get the values instead of using the original s.getCharCodeAt();

Was:
blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( i % 32 );
Now this:
blocks[ i >> 5 ] |= ( s[ i / 8 ] & mask ) << ( i % 32 );


Re benchmarking - I hadn't done any, but I have now.

Initially it was slower than the original version by approx 13%.

I optimised it a bit and now it runs ever so slightly faster than the original 
one
(about 4% faster)

This is the optimisation change, removed this code (in function hash):
  for(var i:int = 0; i<len; i++){
    ba.writeByte(s.charCodeAt(i));
  }
And replaced with this:
  ba.writeUTFBytes(s);  

This converts the string to a byte array in one fell swoop.   I've attached a 
new
version with the optimised code included.

Regards,
Mark Lynch

Original comment by [email protected] on 4 Jul 2008 at 2:37

Attachments:

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
Mike,
In case you wish to reproduced the benchmarks, here is the code I used is below.

I set up two projects with the corelibs  placed in the src folder and ran this 
with
modified and original versions.

Timings I got were on 3 runs were:
Original: 3865,3722,3809, AVG 3799
Patched 1: 4413,4314,4140 AVG 4289
Patched 2: 3625,3561,3797 AVG 3661


Code snippet:
package {
    import com.adobe.crypto.MD5;
    import flash.display.Sprite;
    import flash.utils.getTimer;

    public class md5benchOrig extends Sprite
    {
        public function md5benchOrig()
        {
            var string:String = "asda asd  da da da dasd a dasd asdasdadadad a dasda asd  da
da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a 
dasda
asd  da da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd 
asdasdadadad
a dasda asd  da da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd
asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a dasda asd  da da 
da
dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a dasda 
asd 
da da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd 
asdasdadadad a
dasda asd  da da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd
asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a dasda asd  da da 
da
dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a dasda 
asd 
da da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd 
asdasdadadad a
dasda asd  da da da dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd
asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a dasda asd  da da 
da
dasd a dasd asdasdadadad a dasda asd  da da da dasd a dasd asdasdadadad a dv";
            var hashed:String = "";
            var startTime:uint = getTimer(); 
            for(var i:int; i < 1000; i++){
            hashed = MD5.hash(string);
            }
            var elapsedTime:uint = getTimer() - startTime;
            trace(hashed);
            trace('Time taken: ' + elapsedTime);            
        }
    }
}

Original comment by [email protected] on 4 Jul 2008 at 2:43

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
I have checked in the changes (revision 49).

Could someone post a simple test case / cases for hashBinary? ill add them to 
the
test suite.

Original comment by mikechambers on 6 Jul 2008 at 8:30

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024

Original comment by mikechambers on 6 Jul 2008 at 8:30

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024

Original comment by mikechambers on 7 Nov 2008 at 7:28

  • Changed state: Fixed

from as3corelib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.