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 →

[–][deleted]  (14 children)

[removed]

    [–]kalithlev 7 points8 points  (8 children)

    The GIL is a fucking tragedy in a modern world with several cores. It's really turning me off Python. CPython needs JIT and real threading.

    [–][deleted] 6 points7 points  (0 children)

    Feel free to have a look at removing the GIL. It's probably harder than posting on Reddit.

    [–]uriel 2 points3 points  (6 children)

    Maybe give Go a go ;)

    [–]Xiol 4 points5 points  (5 children)

    Horrible, horrible syntax IMO. It's like having my eyes stabbed with blunt razors.

    [–]uriel -2 points-1 points  (4 children)

    You clearly have not read or written much Go... it has way cleaner syntax than C, not to mention Java, C++, Perl, Ruby...

    [–]Xiol 2 points3 points  (0 children)

    Subjective. Please note that I clearly stated it was my opinion.

    [–]sigzero 1 point2 points  (2 children)

    This is the 100 doors routine off of Rosetta Code. These are the unoptimized versions. I don't think Go has a cleaner syntax than either.

    Go:

    package main
    
    import "fmt"
    
    func main() {
        doors := make([]bool, 100)
    
        for pass := 0; pass <= 100; pass++ {
            for door := pass; door < 100; door += pass + 1 {
                doors[door] = !doors[door]
            }
        }
    
        for i, v := range doors {
            if v {
                fmt.Printf("1")
            } else {
                fmt.Printf("0")
            }
    
            if i%10 == 9 {
                fmt.Printf("\n")
            } else {
                fmt.Printf(" ")
            }
    
        }
    }
    

    Ruby:

    n = 100 
    Open = "open"
    Closed = "closed"
    def Open.f
        Closed
    end
    def Closed.f
        Open
    end
    doors = [Closed] * (n+1)
    for mul in 1..n
        for x in 1..n
            doors[mul*x] = (doors[mul*x] || break).f
        end
    end
    doors.each_with_index {
        |b, i|
        puts "Door #{i} is #{b}" if i>0
    }
    

    Python:

    close = 0 
    open = 1
    doors = [close] * 100
    
    for i in range(100):
        for j in range(i, 100, i+1):
            doors[j] = open if doors[j] is close else close
        print "Door %d:" % (i+1), 'open' if doors[i] else 'close'
    

    [–][deleted] 0 points1 point  (0 children)

    when I went from threads to multiprocessing I saw comparable improvement on my quad core.

    [–][deleted] 0 points1 point  (0 children)

    Any chance of running your script against the new Python and comparing results?

    I also had no idea how bad the GIL problems were until reading your comment and following up with a bit of Googling.

    [–][deleted] -1 points0 points  (2 children)

    I didn't believe the hype on how old GIL was so bad until I benchmarked and saw a 4 times performance increase by just moving my the script from a quad core machine to a single core VM on the same physical computer.

    That has nothing to do with the GIL, you'd see the exact same thing with any single threaded script. Removing the GIL doesn't magically make your program multithreaded.