Try to catch or print the conversion rate in julia - (Julia 73 seconds, Python 0.5 seconds)

I played with Julia because she seems syntactically similar to python (I like), but claims to be faster. However, I tried to do a similar script to what I have in python for tesing, where the numerical values ​​are in a text file that uses this function:

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

For some reason, it takes a long time for a text file with a reasonable number of lines of text (~ 500000).
Why should it be? Is there a better way to do this? What common language feature can I understand from this to apply to other languages?

Here are two exact scripts that I ran over time 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())
+3
3

, float64_isvalid , (a) , (b ) .

, (:) try catch isFloat ( ).

:

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"))

100 000 10 , 50% , Python 4.21 , Julia 2,45 .

+5

, , , julia, , SO, , . , , , (1) try/catch , (2) try/catch , - , . , , . , , , . , , , , Julia - .

+5

Python , . . Python , ?. Python , ( - ). , , - , . , Julia try/catch - . , - , , .

, Julia, , API, . , - , , , . API, , , Julia - . , API: https://github.com/JuliaLang/julia/issues/5704. , .

+3

All Articles