import math


def stdev(valuelist, mean=None):
    """ Returns standard deviation of a list.
        Tested equivalent to but faster than numpy.std

        If the mean is already available it can be passed in as a parameter to avoid recomputation"""
    N = float(len(valuelist))
    if mean is None: mean = math.fsum(valuelist) / N
    VarList = [(val - mean) ** 2 for val in valuelist]
    return math.sqrt(math.fsum(VarList) / N)