Question: I have been playing with Julia because it seems syntactically similar to python (which I like) but claims to be faster. However, I tried making a similar script to something I have in python for tesing where numerical values are within a text file which uses this function:

```
function isFloat(s)
    try:
        float64(s)
        return true
    catch:
        return false
    end
end

```

For some reason, this takes a great deal of time for a text file with a reasonable amount of rows of text (~500000).  

Why would this be? Is there a better way to do this? What general feature of the language can I understand from this to apply to other languages?

Here are the two exact scripts i ran with the times for reference:

python: ~0.5 seconds

```
def is_number(s):
    try:
        np.float64(s)
        return True
    except ValueError:
        return False

start = time.time()
file_data = open('SMW100.asc').readlines()
file_data = map(lambda line: line.rstrip('\n').replace(',',' ').split(), file_data)

bools = [(all(map(is_number, x)), x) for x in file_data]
print time.time() - start

```

julia: ~73.5 seconds

```
start = time()
function isFloat(s)
    try:
        float64(s)
        return true
    catch:
        return false
    end
end
x = map(x-> split(replace(x, ",", " ")), open(readlines, "SMW100.asc"))

u = [(all(map(isFloat, i)), i) for i in x]

print(start - time())

```

Answer: 
Note also that you can use the [float64\_isvalid](http://docs.julialang.org/en/latest/stdlib/base/?highlight=float64_isvalid#Base.float64_isvalid) function in the standard library to (a) check whether a string is a valid floating-point value and (b) return the value.

Note also that the colons (`:`) after `try` and `catch` in your `isFloat` code are wrong in Julia (this is a Pythonism). 

A much faster version of your code should be:

```
const isFloat2_out = [1.0]
isFloat2(s::String) = float64_isvalid(s, isFloat2_out)

function foo(L)
    x = split(L, ",")
    (all(isFloat2, x), x)
end

u = map(foo, open(readlines, "SMW100.asc"))

```

On my machine, for a sample file with 100,000 rows and 10 columns of data, 50% of which are valid numbers, your Python code takes 4.21 seconds and my Julia code takes 2.45 seconds.
Python is oddly ambiguous on the subject of whether using exceptions for control flow is good or bad. See [Python using exceptions for control flow considered bad?](https://stackoverflow.com/questions/7274310/python-using-exceptions-for-control-flow-considered-bad). But even in Python, the consensus is that user code shouldn't use exceptions for control flow (although for some reason generators are allowed to do this). So basically, the simple answer is that you should not be doing that – exceptions are for exceptional situations, not for control flow. That is why almost zero effort has been put into making Julia's try/catch construct faster – you shouldn't be using it like that in the first place. Of course, we will probably get around to making it faster at some point.

That said, the onus is on us as the designers of Julia's standard library to make sure that we provide APIs that never force you to use exceptions for control flow. In this case, you need a function that allows you to try to parse something as a floating-point value and indicate whether that was possible or not – not by throwing an exception, but rather by returning normal values. We don't provide such an API, so this ultimately a shortcoming of Julia's standard library – as it exists right now. I've opened an issue to discuss this API design question: <https://github.com/JuliaLang/julia/issues/5704>. We'll see how it pans out.