![]() ![]() I hope my logic is correct - it's very easy to make a mistake in this kind of tedious bit work. The whole trick is expressing it in string format with RFC compliance, and it's most tightly accomplished with 16 bytes of random data, an unrolled loop and lookup table. The funny thing is, generating 16 bytes of random data is the easy part. But with four variables assigned random data up front, then using the lookup table, and applying the proper RFC bits, this version smokes them all: I tried this once with a single random variable, r, that I kept reassigning, and performance tanked. ![]() Since we're looping a fixed number of times, we can technically write this all out by hand. The final optimization technique to apply - unroll the loop. Though it had fewer iterations, the inner logic was complicated by the increased processing, and it performed the same on desktop, and only ~10% faster on mobile. I tried an e6() that processes 16-bits at a time, still using the 256-element LUT, and it showed the diminishing returns of optimization. Interested in how? I've put the full source on and on įor an explanation, let's start with broofa's code: So by my 6th iteration of optimizations, I beat the most popular answer by over 12 times, the accepted answer by over 9 times, and the fast-non-compliant answer by 2-3 times. Note: 500k iterations, results will vary by browser/CPU. Not really, but it's easy if you follow along.īut first, my results, compared to broofa, guid (the accepted answer), and the non-rfc-compliant generateQuickGuid: Desktop Android Indeed, joelpt even decided to toss out an RFC for generic GUID speed with generateQuickGUID.īut, can we get speed and RFC compliance? I say, YES! Can we maintain readability? Well. Awesome!īut if you're looking at that regular expression, those many replace() callbacks, toString()'s and Math.random() function calls (where he's only using four bits of the result and wasting the rest), you may start to wonder about performance. RFC4122 compliant, somewhat readable, and compact. Broofa's answer is pretty slick, indeed - impressively clever, really. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |