<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
<style>BODY{font:10pt Tahoma, Verdana, sans-serif}</style></head><body>
Hi,<div><br></div><div>I want to reverse the bytes of a bitstring as fast as possible. There is not a erlang BIF that does this, so I googled some possible solutions:</div><div><br></div><div><div>Fun1 = fun(B) -> S = size(B)*8,<<X:S/integer-little>>=B, <<X:S/integer-big>> end.</div></div><div>Fun2 = fun(B) -> binary:list_to_bin(lists:reverse(binary:bin_to_list(B))) end.</div><div><br></div><div>Fun1 = ~37 microseconds when executing Fun1(<"terribly">).</div><div>Fun2 = ~16 microseconds when executing Fun2(<"terribly">)</div><div><br></div><div>But a simple reverse of a list of integers is much, much faster:</div><div><br></div><div>timer:tc(lists, reverse, ["terribly"]) = ~1 microseconds.</div><div><br></div><div>Are there other options or do I need to write a new BIF function? </div><div><br></div><div>Regards,</div><div><br></div><div>Ward Bekker</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></body></html>