Hello, > (aset-byte dst dst-offset (byte sample))
Most of the time, aset is faster than aset-TYPE. Especially when, like here, types are known. If you profile your code, you should see most of the time is in Reflect.Array.set or something similar, and that should disappear if you want your code to perform well. Best, Nicolas. > (aset-byte dst (inc dst-offset) (byte (bit-shift-right sample > 8)))) > (recur (inc src-offset) (unchecked-add 2 dst-offset))))) > > > Adding type coercions helped a bit but it's still too slow. In Java > I wrote this method: > > public static void shortsToBytes(short[] src, byte[] dst, int len) > { > int idx = 0; > short s; > > while (len-- > 0) { > s = src[idx]; > dst[idx*2] = (byte)s; > dst[idx*2+1] = (byte)(s>>>8); > idx++; > } > } > > > Then I timed them under both Clojure 1.0 and 1.1.0-SNAPSHOT and got > similar results. > > [...] > (doseq [n (range 5)] > (time (shorts-to-bytes a b 512000)) > (time (ArrayConverter/shortsToBytes a b 512000)) > (println)) > > > "Elapsed time: 516.527512 msecs" > "Elapsed time: 32.316904 msecs" > > "Elapsed time: 472.034037 msecs" > "Elapsed time: 5.096593 msecs" > > "Elapsed time: 437.755411 msecs" > "Elapsed time: 4.10872 msecs" > > "Elapsed time: 535.864767 msecs" > "Elapsed time: 3.106442 msecs" > > "Elapsed time: 880.127444 msecs" > "Elapsed time: 3.124339 msecs" > > > So Java outperforms Clojure by two orders of magnitude. > > Is there anything wrong with my code? I've been fine-tuning this code > for a couple of days now, to no avail. > > > Thank you and keep up! > Matt. > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---