Comments (7)
Original comment by mikechambers
on 2 Jul 2008 at 4:46
- Changed state: Accepted
- Added labels: HasAPatch
from as3corelib.
>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.
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.
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.
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.
Original comment by mikechambers
on 6 Jul 2008 at 8:30
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
from as3corelib.
Original comment by mikechambers
on 7 Nov 2008 at 7:28
- Changed state: Fixed
from as3corelib.
Related Issues (20)
- BSD License
- PSD parser
- JSONEncoder bug on UTF-8 chars
- Request for StringUtil.contains
- Bug: JSONDecoder does not accept string ending in \u-escape sequence HOT 2
- Enhancement: Use a timer to close the FileTarget log stream. More efficient during heavy logging
- Escaped single quote is not correctly decoded
- Use "valueOf()" to customize JSON object
- Add line numbers to parse errors HOT 2
- JSONParseError: Unexpected c encountered
- After unwatch() is called in FileMonitor, eventListener is removed but is never re-added on watch().
- JSONDecoder fails with token null reference when closing right brace is missing
- FileMonitor onTimerEvent does not fire
- URI.makeAbsoluteURI does not handle local windows filepaths properly HOT 1
- JSON doesn't encode ObjectProxy and ManagedObjectProxy correctly
- JSON Object Problem within ArrayCollection
- JSONParseError: Unexpected e encountered HOT 1
- JSONParseError: Unexpected c encountered
- The HMAC-SHA1 signature generated is different for Ubuntu JAUNTY
- [deleted issue]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from as3corelib.