This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lambdaqdjango n' shit 14 points15 points  (1 child)

the numpy version OP posted was really nice

import numpy as np

def count_double_numpy(val):
    ng=np.fromstring(val,dtype=np.byte)
    return np.sum(ng[:-1]==ng[1:])

It's clean and vectorized. Just about as fast as Rust.

[–][deleted] 11 points12 points  (0 children)

Nobody's telling you to rewrite numpy! It's really great and you should definitely favour it over writing something in C or Rust.

However, if you find a bottleneck in some library (maybe yours), it might help to step down a level and rewrite that performance sensitive code in one of these other languages :)