Python is Too Slow

Поделиться
HTML-код
  • Опубликовано: 27 июл 2024
  • Recorded Offline at 26.09.2021
    References:
    - Porth Source Code: github.com/tsoding/porth
    - Porth Development Playlist: • Making Programming Lan...
    - Project Euler: projecteuler.net/
    - Project Euler Solving Stream: • I made a whole Languag...
    - Porth Simulation in Go: github.com/drocha87/go-porth
    - PyPy: www.pypy.org/
    Support:
    - Patreon: / tsoding
    - Twitch Subscription: / tsoding
    - Streamlabs Donations: streamlabs.com/tsoding/tip
    Feel free to use this video to make highlights and upload them to RUclips (also please put the link to this channel in the description)
  • НаукаНаука

Комментарии • 187

  • @pedro_alonso
    @pedro_alonso 2 года назад +175

    "Python is not slower than C!"
    *shows code that has byte magic, and assembly in the middle*

    • @Muttisuri
      @Muttisuri 2 года назад +8

      However, the test point is with list operations not byte magic and assembly.

  • @Hobbitstomper
    @Hobbitstomper 2 года назад +65

    Once your language becomes self-hosted (compiler written in your own language) so that you no longer have to bootstrap, that will be an amazing feeling for anyone involved in the project.

  • @greob
    @greob 2 года назад +90

    22:26 "that's why I'm unemployed"
    That cracked me up. xD

  • @purplemossclump5505
    @purplemossclump5505 2 года назад +3

    Very cool video, seeing the process of profiling and troubleshooting porth was incredibly entertaining. The only thing I can think of that could be improved is the distinct lack of green frogs. In your future videos consider including more green frogs.

  • @jorgegomes83
    @jorgegomes83 2 года назад +21

    14:03 yes, you can set 0 to the first enumerand and the auto() will follow.

  • @kisinja4582
    @kisinja4582 2 года назад +5

    "oh don't tell me he switches to C AGAIN!!!"

  • @Diamonddrake
    @Diamonddrake 2 года назад +3

    In college we could choose which language we used for algorithms homework, there were run duration requirements for full marks and people who used python got a 5x time bonus because it’s so much slower. I’ll never forget that.

    • @asnaeb2
      @asnaeb2 2 года назад

      That would mean their algorithms needed to be faster than yours cause Python is about 200x slower than pure C.

  • @keldwikchaldain9545
    @keldwikchaldain9545 2 года назад +2

    The fact that 15 million appends was 100 seconds in your interpreter and was 6 seconds with pops in the stack stresstest tells me that your if ladder for all ops is very slow and could be optimized by putting common operations earlier in the ladder and potentially by eliminating it altogether and turning it into a map lookup to find a function pointer to call.

  • @SR-zi1pw
    @SR-zi1pw 2 года назад +3

    I am addicted to the channel

  • @eukaryote0
    @eukaryote0 2 года назад +4

    Tso did you try to run porth.py with python -O (disabled asserts) to check if it runs any faster?

  • @petros_adamopoulos
    @petros_adamopoulos 2 года назад +7

    I made sim run many times faster by avoiding the "elifs" with a map of functions. Alternatively, just putting the most common intrinsics like DUP, SWAP, DROP etc first in the "elifs" already makes it noticeably faster, for obvious reasons.
    I find sim pretty usable now actually. With pypy, euler problem04 takes 10 seconds, and my PC is clocking at like a 1GHz, so.

  • @LaPingvino
    @LaPingvino 2 года назад +3

    when I see you struggle with the Python enum, I'm so happy with the way Go does enumerations xD

    • @LaPingvino
      @LaPingvino 2 года назад

      update: what is that travesty with the time function? :O

  • @jorgegomes83
    @jorgegomes83 2 года назад +55

    30:07 One simple optimization for the stack is to initialize it with a sequence of zeroes of some size (maybe 1k is enough) and and instead of pushing and popping, you just do common getitem and setitem, with help of some sort "stack pointer" local var. Probably append and pop deals with memory allocation/freeing and maybe that's what makes it slow.

    • @craiglobo2165
      @craiglobo2165 2 года назад +19

      Or you could use a numpy arrays though it would add a dependency Or use the deque type where searching is O(1) rather than O(N)

    • @jorgegomes83
      @jorgegomes83 2 года назад +3

      @@craiglobo2165 agreed. I always forget to use these...

    • @homelikebrick42
      @homelikebrick42 2 года назад +2

      @@craiglobo2165 Array indexing is O(1)

    • @HiHi-ur3on
      @HiHi-ur3on 2 года назад +1

      @@homelikebrick42 I'm pretty sure it would be O(n). Python would probably used linked lists which are non contiguous in memory.

    • @jetison333
      @jetison333 2 года назад +10

      @@HiHi-ur3on python does not use linked lists.

  • @20dareason09
    @20dareason09 Год назад +2

    cython is also a cool alternative if you like python syntax. It compiles python code to C with "appropriate" levels of interaction with Python's C libraries. It has been around for a long time.
    A bit of a learning curve, but I think it works quite nicely.

  • @FADHsquared
    @FADHsquared 2 года назад +6

    If you're a beginner learning Python, don't worry because this is the right time. By the time you're pretty good at python, version 3.11 will be released, which targets a 2x performance improvement of the vanilla interpreter (CPython)

  • @cptclutch6994
    @cptclutch6994 2 года назад +1

    Would using switch() help? Or maybe python has labels? Or function pointers?

  • @MrGranddy
    @MrGranddy 2 года назад

    Since you started the project and created the "stack" I was telling myself this will blow up big xd

  • @adrianpolv8143
    @adrianpolv8143 2 года назад +8

    You should consider hiding operations that weren't used from displaying and maybe even sorting list by time or use count

  • @skaruts
    @skaruts 2 года назад +2

    I wish I could make my own programming language. A compiled crossover between C and Lua, free of bloat, free of safety paranoias, and with optional typing, and begin-end blocks (implicit begin, like Lua's).
    Alas, I still have a lot to learn and a looong way to go. :)

  • @rodelias9378
    @rodelias9378 2 года назад +1

    Really interesting one! Thanks!!

  • @nic37ry
    @nic37ry 2 года назад +6

    On my laptop using pypy for problem 4, on windows, it runs kinda fast
    906609
    wall: 00m:04s:111ms
    user: 00m:00s:62ms
    kernel: 00m:00s:31ms

  • @arielfuxman8868
    @arielfuxman8868 2 года назад +1

    Hi man, great videos!
    Where are you from? I hear you have an accent
    And could you arrange your videos in playlists so that it will be easier to track series?

  • @ZX48K
    @ZX48K 2 года назад +44

    Surely the Go version should be called Gorth? :)

    • @electricz3045
      @electricz3045 2 года назад +3

      C version: Corth, Java Version: Jarth and so on

    • @Muttisuri
      @Muttisuri 2 года назад +3

      I'm waiting for Haskrth (working title) XD

  • @Blubb3rbub
    @Blubb3rbub 2 года назад

    The append/pop loop gets a lot faster for me if I don't start it with an empty list. I used %timeit in IPython to measure it and it goes from 23.4ms±20.9 µs down to 8.97ms±58.3 µs for 100.000 Iterations. I assume this is because python deallocates/reallocates the memory of the list if it gets empty?

  • @HaouasLeDocteur
    @HaouasLeDocteur 2 года назад +3

    28:55 knowing exactly just how slow python is, I was thinking “oh dear, you’re in for a surprise, boss” 😂
    I spat my drink when he was like “are you fucking kidding me??”

  • @penndrive
    @penndrive 2 года назад +9

    Love the content, love the voice and the quality of the audio. Just one recommendation, you should use a de-esser or eq to lo the sibilance in your S and CH, you could make it a preset and forget about it for the rest of your youtube carreer!. Amazing content! Keep it up

  • @haxidenti6001
    @haxidenti6001 2 года назад +2

    What a nice font. Can u give me a link to download that ? Is it `Losevka` or `JetBrains Mono` ?

  • @rysw19
    @rysw19 Год назад

    22:25 “That’s why I’m unemployed.” Lol Tsoding makes my day, I love this series

  • @meh2414
    @meh2414 2 года назад

    mate, I guess you should use smth like np.ndarray with dtype=int instead of plain list, because list by default allocates each element on the heap separatly (to keep list dynamicly typed) and it cannot get advantage of knowing that you're using only ints in it

  • @rooutbrouse880
    @rooutbrouse880 2 года назад +20

    honestly expecting some optimisations for "stack" :)
    pypy was unexpected solution for me.

  • @easteregg8699
    @easteregg8699 2 года назад +1

    what was the tool used for zooming onto python? is that a obs thing?

  • @pavelperina7629
    @pavelperina7629 2 года назад

    I guess using list and vector is not the same. I'm not sure how list in Python is implemented, but C++ std::vector allocates one byte if you push into it (which is slow) and doubles the capacity when new element is inserted and does not fit, copying or moving all objects to newly allocated vector. But as when you push and pop capacity remains equal to one, it just internally increases size, assigns 69 and decreases size. It's not the stack operation. I'm not sure how to use stack directly, maybe by calling empty function which stores instruction pointer at the stack, but it does more. Reading from vector in Microsoft implementation of std::vector checks if you are accessing valid element and integrity of the vector, which is why debug mode on WIndows is painfully slow.
    I guess std::list in C++ is very similar to deque (double ended queue) and std::stack or std::queue are deque with certain operations forbidden. Stack can be replaced by vector which is much faster.
    In python it might be the same. Pushing means that you need to update head and tail of list to point at inserted element and allocate memory for it and free it which is very slow.

  • @monsieuralexandergulbu3678
    @monsieuralexandergulbu3678 2 года назад +5

    That's why I'm writing python compiler

  • @fizipcfx
    @fizipcfx 2 года назад

    It is a very very small thing but i have to say, you can open a link in new tab using mouse middle click

  • @andy_lamax
    @andy_lamax Год назад

    a missed opportunity to call Go-Porth, gorth

  • @TheDRAGONFLITE
    @TheDRAGONFLITE 2 года назад +4

    this guys voice is amazing

  • @mateuscanelhas5662
    @mateuscanelhas5662 2 года назад +37

    If i'm not mistaken, python's pop for lists is O(N). Try switching to a O(1) implementation. It should be as easy as :
    ```
    from collections import deque
    stack = deque()
    ```

    • @atrumluminarium
      @atrumluminarium 2 года назад +1

      That's what I was thinking too deques are more optimised for this

    • @begga9682
      @begga9682 2 года назад

      The test program he had is still incredibly slow with that, but I guess it would help in the emulator

    • @Avanta1
      @Avanta1 2 года назад +2

      list.pop is not O(n). Why would it be?

    • @DJminecraft2445
      @DJminecraft2445 2 года назад +9

      @@Astana1337 pop() is not the same as pop(0) and pop() is O(1)

    • @jensrenders4994
      @jensrenders4994 2 года назад

      @@DJminecraft2445 Who said pop()? they said pop.

  • @lionkor98
    @lionkor98 2 года назад +1

    It would be smart to show time per operation on average

  • @ofekshochat9920
    @ofekshochat9920 2 года назад +2

    oh really? thats a surprise ofc. only a select few know this. btw love your videos

  • @realGBx64
    @realGBx64 2 года назад +1

    Did he just miss it that the 64bit read and write operations are full of swaps?

  • @happywednesday6741
    @happywednesday6741 2 года назад

    Shouldn't you use the timeit function to be timing these?

  • @user-pm2ru6ir6n
    @user-pm2ru6ir6n 2 года назад +2

    Лагает в load64, store64 потому что там по 8мь(+-) dup`ов, swap`ов и over`ов. Хотя автор сказал, что не из за этого (access mem 64).

  • @ThankYouESM
    @ThankYouESM 2 года назад +1

    Curious... why not make a Py3-to-C++ (Lightweight) standalone 3D Engine whereas the the C++ initially interprets which variable types to assign? I did that with JS which worked perfect.

  • @hatema
    @hatema 2 года назад +3

    Euler ❌
    Oiler ✅

  • @Unaimend
    @Unaimend 2 года назад +2

    Doesn't python have a real bad Big O for pop from a list?
    Nvm. only for list.pop(0)
    And as far as I know, python list are arrays under the hood, and depending on how "array-growth" is implemented there is the possibility that python has to copy the memory a lot of times.
    You could use sth. like flamegraphs to see were the python vm spends a lot of its time. But in the just switching to pypy is a lot easier and maybe CPython is really just freaking slow in this case

  • @bugr33d0_hunter8
    @bugr33d0_hunter8 2 года назад

    i almost didn't recognize you. You been going to the gym, seem more fit. That's good.

  • @hyper-stack
    @hyper-stack 2 года назад

    what is the name of the software u use to code in the video?

    • @atrumluminarium
      @atrumluminarium 2 года назад +2

      Emacs I believe

    • @lalmiahmed3573
      @lalmiahmed3573 2 года назад

      VIM

    • @Cons-Cat
      @Cons-Cat 2 года назад

      @@lalmiahmed3573 That's not Vim .. look at the status bar. He's using YAS, Company, and ElDoc. Obviously this is GNU Emacs.

  • @botbeamer
    @botbeamer 2 года назад +1

    Cython would be good to try for this

  • @eukaryote0
    @eukaryote0 2 года назад +5

    Semicolons are too slow in python

  • @blitzpark1250
    @blitzpark1250 2 года назад +1

    I am always like a skeptic about the thing that if I write a language(say a language similar to C but with no pointers and with a boehm gc) in ruby (which is more slower than python) and bootstrap it. Will it produce as fast software as C? Like a recursive code for fib(45) in pypy takes around 16-18seconds on my computer and same thing in gcc takes around 6-8seconds!... Is it possible to make a compiler which can atleast near performant to C lang.... (Note: I quote the example to express my question so that it can be understood).

    • @bigmistqke
      @bigmistqke 2 года назад

      W porth he can emulate it in python (slow) and can compile it to assembly (fast, but probs a bit slower then C cause optimizations)

    • @Roxve
      @Roxve 3 месяца назад

      C Compilers is complex and does lots of optimization, if you manged to get the same optimization level for your compiler than yes, you can also output stuff other than assembly like llvm and C code both would achive same speed and you will not need to do optimization

  • @kurtmayer2041
    @kurtmayer2041 2 года назад +2

    people use cpython because it's the default and reference implementation (and pypy has ... issues ... with c modules)

  • @desertfish74
    @desertfish74 2 года назад +1

    Instead of a list, use a deque. And instead of huge if else if chains (for the bytecode) use a dictionary that maps the code to the function, to get o(1) lookups.

    • @ithaca2076
      @ithaca2076 2 года назад

      dont know why i never thought of that.. but thats really creative and useful thank you

  • @iWillAvert
    @iWillAvert 5 месяцев назад

    From the future!
    I just ran the same stack stress test using all of the latest versions of Python, PyPy, and C++. The results are wild:
    Python 3.11.7 - 1.3s. Respectable now!
    C++ - 0.5s with optimizations off. Pretty good! With optimization level 3 it dropped to 0.07s! (compiled using g++ as tsoding did)
    PyPy 7.3.15(Python 3.10.13) - 0.02s!! It somehow is even faster than C++ fully optimized.
    Now, that being said, I also have had many instances where PyPy ran SIGNIFICANTLY slower than regular Python, so take it for what you will. That is impressive though. If only it was always like that, it would make PyPy and sometimes even Python a real speed contender 😂

  • @craiglobo2165
    @craiglobo2165 2 года назад +6

    lists aren't made for speed or efficiency especially pop and append methods. Use a NumPy array or Initialize all values to None for the max number of operations for the stack and use a stack pointer variable

    • @jensrenders4994
      @jensrenders4994 2 года назад +1

      lists are made for efficient appends.

    • @jensrenders4994
      @jensrenders4994 2 года назад +1

      @@greggoog7559 That has little to do with JavaScript and the list type. It has more to do with jit compilation.

    • @jensrenders4994
      @jensrenders4994 2 года назад +1

      @@greggoog7559 Because it is a language, just like JavaScript is not jit compiled. V8 is a jit compiler for JavaScript, which you probably use. PyPy is a jit compiler for python.

    • @patryk_49
      @patryk_49 2 года назад

      @@jensrenders4994 You are underestimating the imortance of data structures.
      Also if your list doesn't contantain 50 000 elements and thoose elements are not very large(which is like 0.95 of all cases) then the data structure with the fastest appends is plain array.

    • @jensrenders4994
      @jensrenders4994 2 года назад +1

      @@patryk_49 in which implementation of which language?

  • @griof
    @griof 2 года назад

    13:45 are you serious? Hahaha that was funny.

  • @steffenmuhlen9346
    @steffenmuhlen9346 2 года назад

    List ist optimized for convenience
    Like almost everything in python

  • @ivypierlot
    @ivypierlot 2 года назад

    haskell moment

  • @suzanne4300
    @suzanne4300 2 года назад +4

    Write Porth in Porth

    • @bigmistqke
      @bigmistqke 2 года назад +1

      That's the goal. Really looking forward to the step of self-hosting.

  • @atrumluminarium
    @atrumluminarium 2 года назад +8

    List is slow in python. My suggestion is to maybe look into python's native arrays (just `import array`) since you're using the same datatype for the elements or the deque datastructure (i think `from collections import deque`).
    Alternatively there's always Cython, however this may be a bit too much of an investment for just a simulation mode

    • @markervictor
      @markervictor 2 года назад +2

      No, python’s list is like c++ std::vector. Linked list is a queue, but it made not for stack tasks absolutely. List is a the fastest native python stack solution.

    • @atrumluminarium
      @atrumluminarium 2 года назад

      @@markervictor I had a quick look online and you're right, putting an edit in my comment

    • @danilo2735
      @danilo2735 2 года назад

      it is not a linked list

    • @atrumluminarium
      @atrumluminarium 2 года назад

      @@danilo2735 yes I know a previous commentor pointed ot out to me. I ammended my comment

    • @danilo2735
      @danilo2735 2 года назад

      @@atrumluminarium Sorry. I didn't notice the other comment.

  • @electricz3045
    @electricz3045 2 года назад +3

    Now someone need to do a tool that convert python to this language and probably obfuscate it and compile it to a .exe or .bin in Linux and so on 😅

    • @FaranAiki
      @FaranAiki 2 года назад +1

      Linux is ".bin"? I never see someone said that. Both are ".bin" if we exclude file extension. Converting a Python to this language is kind of... a little impossible. Python is filled with many built-in function/modules.

  • @Michael-rc5ks
    @Michael-rc5ks 2 года назад

    Simply put, pypy doesn't support the latest features, especially the walrus operator which I use a lot

  • @mezzer34
    @mezzer34 2 года назад

    *Opens cpp doc to show example*
    *Happy Programmer noises*

  • @DavidRodriguez-df4gt
    @DavidRodriguez-df4gt 2 года назад +1

    Takeaway : Python may be easy to pick up, but hard to master

    • @kyrylmelekhin2667
      @kyrylmelekhin2667 2 года назад +1

      Why would you bother mastering something that is a shity language by design? Only to realize that at the end of the day, the language sucks and there is nothing you can do about it? To be implementing more layers of abstraction and workarounds that will get exponentially more difficult to remove in the future? Is this something to be proud of for the next generations to come? Opinions lie, numbers don't. If python is this slow it should of been deprecated long time ago and thrown out the window. This is what happens in every other industry except this one.

  • @johannjohannes7214
    @johannjohannes7214 2 года назад

    Wierd my timing in regular cpython are 1.7seconds for 15.000.000 push / pops

  • @Tijan1
    @Tijan1 2 года назад

    start_time = time.perf_counter()
    end_time = time.perf_counter()
    print(end_time - start_time)

  • @RyanKOnk
    @RyanKOnk 2 года назад

    It was never meant to be fast

  • @Measter21
    @Measter21 2 года назад

    After watching this, I profiled my Rust implementation of the simulator with the problem 4 implementation using VTune, which ran it for 2 second's worth of execution to get good data (so executed about 10 times).
    Of that 2 second runtime, a full 500ms was spent executing Swap. Digging a little deeper, 400ms is spent on the single instruction used to load: MOVDQU. It's not like it's hitting RAM because the top of the stack is hot, so I'm a little surprised it takes that long.
    Other hotspots were division at 239ms, and fetching the next instruction at 800ms. Neither are particularly surprising.

  • @Tijan1
    @Tijan1 2 года назад

    stack stress took 0.5 sec with pypy

  • @eukaryote0
    @eukaryote0 2 года назад +3

    1. Claim Python is slow
    2 (optional). Learn Python

    • @ishdx9374
      @ishdx9374 2 года назад

      yeah but.. python is slow.. by design, it can't be faster than C or C++, heck even go

    • @FaranAiki
      @FaranAiki 2 года назад +1

      ​ @ishdx, Go is compiled, by design, to a native machine. But, the size of the result file is very big (usually 1 MB). You are comparing an interpreter "programming" language to a compiler "programming" language, that is unfair.

    • @ishdx9374
      @ishdx9374 2 года назад

      @@FaranAiki yes but do you realize that to run a python executable you need the runtime, and the runtime is far above the 1 MB threshold, CPython runtime is about 4 MB which is far more than something like go result executable, but that's only the runtime, because you also need to bundle libraries. in result if you want to have a final EXE file that an end user can execute without going through installing python and dependencies, you have to bundle the runtime with the executable, as such resulting executable will be over the 4 mb threshold, which is higher footprint.
      i like python but if you want to go fast, python is probably not the language you need. C/C++ without CRT can give an minimal executable as small as 4kb, without any runtime or dependencies needed.

    • @Cons-Cat
      @Cons-Cat 2 года назад

      @@ishdx9374 The Circuit Python runtime is under 1.5 kb

    • @ishdx9374
      @ishdx9374 2 года назад

      @@Cons-Cat i'm pretty sure it's not possible, can you link some sources? for example i downloaded a patch from their website and it's 1.4~ megabytes, not kilobytes

  • @colinmaharaj
    @colinmaharaj 2 года назад

    Once the language becomes self aware, it will optimize it self 😆

  • @thrinayreddy3379
    @thrinayreddy3379 2 года назад +1

    pypy does not support many usefull libraries like pandas,some numpy functions,many scipy modules and lots of other
    libaries

    • @TsodingDaily
      @TsodingDaily  2 года назад +1

      Yeah, I already encountered problems with pypy when I tried to use it with mypy which uses some internal CPython API :D

  • @longlostwraith5106
    @longlostwraith5106 2 года назад

    Yeah, you assumed that Python lists are arrays... Big mistake.

  • @futurisold
    @futurisold 2 года назад +1

    Try using f strings to format stuff when printing. Much more convenient.

  • @MrRyanroberson1
    @MrRyanroberson1 2 года назад

    28:00
    one thing i found in python is that it's actually way better to use the beginning of a list, NOT the end, for stack-like operations.
    var = [1,2,3]
    var[:0] = [0]
    var == [0,1,2,3]
    var.pop(0)
    var == [1,2,3]
    of course using the end of a list for stack operations means you'll be trawling down the entire list each time. Tuple accessing is faster because, due to their immutability, the computer can create a constant-lookup set of memory locations, whereas lists cannot be optimized by their very definition

    • @MrRyanroberson1
      @MrRyanroberson1 2 года назад

      okay 30:00 shocked me. i had no idea even tiny lists were this slow

  • @rbrezu
    @rbrezu 2 года назад

    You might consider to try to rewrite some parts in cython. It's almost the same grammar.

    • @monsieuralexandergulbu3678
      @monsieuralexandergulbu3678 2 года назад +2

      Cython, not cpython, he already use cpython

    • @barendscholtus1786
      @barendscholtus1786 2 года назад

      In fact, it *is* the same but adds C types in C style or Python compatible style, and the compilation step.

    • @atrumluminarium
      @atrumluminarium 2 года назад

      I'm not sure if he'll find it worth it just for the sake of simulation mode but I guess it's an option

  • @barendscholtus1786
    @barendscholtus1786 2 года назад +12

    If you want to make python programs faster, please use a Jit such as PyPy or Numba, or use libraries with fast C backends such as numpy, or add C types and compilation using Cython.

    • @welltypedwitch
      @welltypedwitch 2 года назад +8

      You might want to watch the video before commenting...

    • @barendscholtus1786
      @barendscholtus1786 2 года назад

      @@welltypedwitch What do you mean? I watched the video... the comments are not any less valid.

    • @bigmistqke
      @bigmistqke 2 года назад +1

      @@barendscholtus1786 because he ended up using pypy as well?

  • @KingJellyfishII
    @KingJellyfishII 2 года назад

    ayy another i3 user in the wild

  • @hansvetter8653
    @hansvetter8653 2 года назад

    Python is definitly slower than C. But you seem to be one of so many who ignore the rich or should I say waste ... or even ... gigantic store of packages, all coded in C ...
    So if your Python-Code is very much slower than it would run in pure C, than you know just one thing for sure ... your Python-Code has an awefull lot of potential for optimizations ... ;-)
    Focus on isolated language statements is anything but has nothing to do with real life applications!
    My future path is writing MVPs in Python and rewrite say optimize it all in Go ... ;-)

  • @0xCAFEF00D
    @0xCAFEF00D 2 года назад

    9:45
    Python has a type in the collections library that does what you want.
    You pass it a lambda or type to default to.
    Code:
    from collections import defaultdict
    d = defaultdict(int)
    # d = defaultdict(lambda: 0) # not needed because the default int is 0
    d["Op1"]
    print(d['Op1'])
    d["Op2"] += 1
    d["Op2"] += 1
    print(d['Op2'])
    Output:
    0
    2
    Of course your list implementation is probably better because I would expect that it produces less interference in performance measurements. But it's good to know.
    Thanks for the interesting video.

  • @mishikookropiridze
    @mishikookropiridze 2 года назад

    Please remove if elif chains and use dictionary for managing

  • @IlhanNegis
    @IlhanNegis 2 года назад

    push pop was eye opening, god even js is better

  • @ujjawalsinha8968
    @ujjawalsinha8968 2 года назад

    Fcuk! I am switching

  • @omaramo190683
    @omaramo190683 2 года назад

    31:04 wtf hahaha

  • @ac130kz
    @ac130kz 2 года назад +1

    deque should be used for stacks, also please remove elif's - use list lookups instead

  • @puncherinokripperino2500
    @puncherinokripperino2500 2 года назад

    why not just port it to c++?

    • @FaranAiki
      @FaranAiki 2 года назад +1

      That is like saying, "Why not rewrite the entire thing into C++?"

    • @puncherinokripperino2500
      @puncherinokripperino2500 2 года назад

      @@FaranAiki yes, don't see any problems

    • @FaranAiki
      @FaranAiki 2 года назад +1

      ​ @Puncherino Kripperino, wait, is this interpreter or compiled language? I do not follow the series.

    • @puncherinokripperino2500
      @puncherinokripperino2500 2 года назад

      @@FaranAiki Porth is compiled language, but Tsoding also implemented the simulation mode, which is basically interpretaition.

    • @FaranAiki
      @FaranAiki 2 года назад +1

      ​ @Puncherino Kripperino, that would be very slow. An interpreted language (Porth) interpreted by an interpreter (Python) by which that interpreter is interpreted by another interpreter (CPU) is of course slow.
      But, still, to rewrite it into C++ takes a lot of effort.

  • @GamingStudiosX
    @GamingStudiosX 2 года назад

    make porth in porth in porth :)

  • @__________________________6910
    @__________________________6910 2 года назад

    Hi--lllo

  • @charlesselrachski34
    @charlesselrachski34 2 года назад

    its not that python is slow but python sucks, when you got better languages now like phix and nim, which give you 1 binary file that has no dependencies , python code it once distribution hell forever

  • @user-ul2mr7cy3f
    @user-ul2mr7cy3f 2 года назад

    акцент топ!

  • @amd9918
    @amd9918 2 года назад

    this is not a news xD its obvious

  • @will2see
    @will2see 2 года назад

    wtf?!

  • @botbeamer
    @botbeamer 2 года назад

    Lol

  • @ac130kz
    @ac130kz 2 года назад

    let's use Pony lang!

  • @templeosdisciple3299
    @templeosdisciple3299 2 года назад

    You're unemployed because you are opinionated!!

  • @user-ft6zh8ny9i
    @user-ft6zh8ny9i 2 года назад

    I noticed for a long time that Python is slow like a turtle on crutches, so I program in C ++. Python is really bullshit Lego for kids.

    • @imadetheuniverse4fun
      @imadetheuniverse4fun 2 года назад

      The guy in this video barely knows how to use Python lol. Then he's surprised that it's "slow".

    • @sibyl4861
      @sibyl4861 2 года назад

      This is the most bullshit take I've ever seen.