When you Over Optimize a Python Function

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 พ.ค. 2023
  • #coding and #programming with #python
  • บันเทิง

ความคิดเห็น • 527

  • @josephjones836
    @josephjones836 ปีที่แล้ว +2505

    Pop emoji. This guy is a troll 🧌 lol

    • @robmulla
      @robmulla  ปีที่แล้ว +305

      It only works when it’s exactly 721 though. Otherwise it could make your computer smell.

    • @mmd8075
      @mmd8075 ปีที่แล้ว +8

      @@robmulla can we add some baby diapers?

    • @felipedidio4698
      @felipedidio4698 11 หลายเดือนก่อน +47

      This comment runs on the GPU
      💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩

    • @JhongHwaMinKkwo
      @JhongHwaMinKkwo 11 หลายเดือนก่อน +9

      @@felipedidio4698my gpu has died. now i bought a new one for my macbook air since there are too much emoji that out of apple’s handle

    • @biomorphic
      @biomorphic 10 หลายเดือนก่อน +4

      @@robmulla it's great considering I am reading this when I am on the toilet taking a shit :-D

  • @Tenly2009
    @Tenly2009 ปีที่แล้ว +4192

    If you use the 🤮 88 times instead of the 💩 721 times, it pipes the code through the flux capacitor and gives you your answer the day before you run it!

    • @robmulla
      @robmulla  ปีที่แล้ว +302

      You must love danger.

    • @walidlam2411
      @walidlam2411 10 หลายเดือนก่อน +17

      Hilarious 😂

    • @cptmorgan92
      @cptmorgan92 9 หลายเดือนก่อน +30

      I tried and you are troll!!
      Suddenly adolf hitler appeared behind me and yelled “HAKENKREUZE!!1!1!! KEIN SCHEIASHAUFEN!!11!”

    • @jdlopez131
      @jdlopez131 6 หลายเดือนก่อน +2

      Hahaha hahaha love it!!!

    • @chrisendacott8765
      @chrisendacott8765 5 หลายเดือนก่อน +1

      What emoji do I need to use to get it to output a hoverboard? I want my hoverboard already.

  • @danishhaider5183
    @danishhaider5183 ปีที่แล้ว +2249

    They had us in the first half, not gonna lie

    • @robmulla
      @robmulla  ปีที่แล้ว +221

      The first suggestion was actually legit 😂 the other two… not so much.

    • @Ir0nically1
      @Ir0nically1 8 หลายเดือนก่อน +8

      ​@@robmullaBut the first one ends the code if the other if statements aren't possible which is better in my opinion

    • @StarfoxHUN
      @StarfoxHUN 6 หลายเดือนก่อน +20

      ​@@Ir0nically1The second one acts like that too, because it returns at the first 'true'.

    • @HAbarneyWK
      @HAbarneyWK 6 หลายเดือนก่อน +11

      ​@@StarfoxHUNit's also way more readable.

    • @rodrigoqteixeira
      @rodrigoqteixeira 6 หลายเดือนก่อน +5

      The return part is true, the poop and the sleep parts are fake

  • @panlis6243
    @panlis6243 6 หลายเดือนก่อน +346

    Imagine your coworker asking on the team group chat why are there 721 poop emojis in the server logs

    • @samueljehanno
      @samueljehanno 5 หลายเดือนก่อน +3

      😂

    • @Smac_Ker
      @Smac_Ker 4 หลายเดือนก่อน +4

      Just reply back with 721 joy 😂 emojis and a quick snooze (or check your phone, anything that takes a second). It will speed up the conversation. Your welcome

    • @Alex-ns6hj
      @Alex-ns6hj 4 หลายเดือนก่อน +1

      @@Smac_Ker and speed up your time at the job too 😅

  • @rotteegher39
    @rotteegher39 5 หลายเดือนก่อน +741

    C++ & C: "We are fast!!!!"
    Meanwhile Python: "Let's add sleep() to make sure this function doesn't run too fast."

    • @TheRandomPerson49
      @TheRandomPerson49 5 หลายเดือนก่อน +12

      😂😂

    • @friedrichmyers
      @friedrichmyers 5 หลายเดือนก่อน +31

      while the language is already shamefully slow

    • @colin398
      @colin398 5 หลายเดือนก่อน +24

      @@friedrichmyers In what way is it shamefully slow? Its not shameful if speed isn't the intention.

    • @Gameplayer55055
      @Gameplayer55055 4 หลายเดือนก่อน +1

      Add time.sleep to mitigate meltdown spectre

    • @friedrichmyers
      @friedrichmyers 4 หลายเดือนก่อน

      @@padre_putativo_suscriptor "of its kind". What kind? Even Javascript is faster. Python is fast only when you're writing it. It is a library language. It is just used to call functions from other libraries whoch use better languages to do real computing. Throw a for loop at Python and you can see how shamefully slow it is. C++ is my preferred language and that's what I would call a fast language. Don't even get started on Assembly. It is a skill issue if C/C++ can't be almost as fast as Assembly. Programming operations that run fast require language that has the ability to be fast in the first place.
      Please Note: "Fast" doesn't mean you get the output right away. "Oh i can see how fast it goes. It is like zap", said the dumb guy whose code was to add two numbers. There is an objective way to measure performance and Python isn't even on the list of winners.

  • @johantaube3022
    @johantaube3022 6 หลายเดือนก่อน +91

    I mean, putting a random delay is a legit thing.
    Customer: build this script!
    Me: *builds super fast script*
    Customer: When I input a number, the script produces the result instantly. It feels like it doesn't even think about the result. Are you sure it works correctly?
    Me: *inserts 1s delay*
    Customer: Ahhh, much better! Now I know it's calculating because it takes a bit of time

    • @heyjakeay
      @heyjakeay 4 หลายเดือนก่อน +22

      This is a legitimate psychological effect designers have noticed when doing "complex" tasks that computers can finish in seconds, it makes the user think the computer is actually thinking about it and instills trust. Used especially and extensively for hotel bookings, flight searches, money calculation sites etc.

    • @schwingedeshaehers
      @schwingedeshaehers 4 หลายเดือนก่อน +1

      ​@@heyjakeayi think it is also used that you can be sure, that it isn't booked multiple times, from different places, and so one

    • @MartinBarker
      @MartinBarker 3 หลายเดือนก่อน +2

      @@heyjakeay citation please i really wanna read that paper and find out everything about that.

    • @Thezftw
      @Thezftw 3 หลายเดือนก่อน +4

      ​@@heyjakeay I often add animations to things like save buttons that run longer than what the process actually takes to run just so that the user doesn't get confused when it finishes in a fraction of a second and they don't see or notice anything.

    • @ZennMagic
      @ZennMagic 3 หลายเดือนก่อน

      @@MartinBarkerTurboTax is one of the more infamous examples of pretending like it's doing something, so they can keep convincing people that filing taxes is hard and definitely something they should take care of instead of the government.

  • @lorisdeluca610
    @lorisdeluca610 ปีที่แล้ว +352

    Just tested in production. Blazingly fast.

    • @marcino6650
      @marcino6650 6 หลายเดือนก่อน +2

      It is so fast that it can be difficult to make it to the toilet and plumber will have a lot of work with 721 💩

    • @phusicus_404
      @phusicus_404 3 หลายเดือนก่อน +1

      More like crappily fast!

  • @JoelRJ
    @JoelRJ ปีที่แล้ว +485

    I'm testing this in prod thanks

    • @robmulla
      @robmulla  ปีที่แล้ว +87

      That’s the only way to properly test new code. 😂

    • @XEQUTE
      @XEQUTE 9 หลายเดือนก่อน +9

      @@robmulla be sure to accredit the author of this algorithm to make any algo O(1)

    • @sniz-mangalore3562
      @sniz-mangalore3562 3 หลายเดือนก่อน

      ​@@robmulla Adding "Drop Database ..." Statement to prod makes your app even faster😂😂😂😂

    • @siajnesdunk
      @siajnesdunk 3 หลายเดือนก่อน

      Prod is also the only real prod-like environment you have, so good idea.

  • @humanrightsadvocate
    @humanrightsadvocate 11 หลายเดือนก่อน +67

    # I'm learning Python, so I took it as a homework assignment
    def poo_721(func):
    def wrapper(*args, **kwargs):
    print("💩" * 721)
    return func(*args, **kwargs)
    return wrapper
    @poo_721
    def calculate_grade(score):
    if score < 60: return "F"
    if score > 89: return "A"
    return chr(74 - score // 10)
    # driver code
    for n in range(101):
    print(n, calculate_grade(n))
    # EDIT: I implemented a poo decorator. The idea being that the poo decorator can be used to optimize many other functions :)

    • @robmulla
      @robmulla  11 หลายเดือนก่อน +8

      Nice! No poop emojis though :/

    • @nightwintertooth9502
      @nightwintertooth9502 5 หลายเดือนก่อน +7

      I would say that this poop is polished but it is in fact decorated.
      You forgot @wraps(func) before your wrapper function. This decorator adds the inner decorator function automatically and avoids additional nesting.
      Ensure to from functools import wraps. Other than that decent job.

    • @HT79
      @HT79 5 หลายเดือนก่อน +2

      Now take it a step further by making an ABCMeta class with overridden __call__ / __new__ to wrap every function of all inherited classes with this decorator.

    • @Be3y4uuK0T
      @Be3y4uuK0T 4 หลายเดือนก่อน

      def calculate_grade(score):
      return 'FDBCA'[score // 10 - 5]
      maybe this faster

    • @JosuaKrause
      @JosuaKrause 4 หลายเดือนก่อน

      @@Be3y4uuK0T forgot time.sleep(1)

  • @jakobullmann7586
    @jakobullmann7586 6 หลายเดือนก่อน +41

    If you had just said “optimize this function by making it slower” and added a sleep for 5ms, I’m sure some people would be routinely doing it now.

    • @AdeogoSosanya-hh6uo
      @AdeogoSosanya-hh6uo 4 หลายเดือนก่อน +1

      I guess he wanted it to be obvious 😂... He actually had me at the first half I wouldn't lie😂

    • @schwingedeshaehers
      @schwingedeshaehers 4 หลายเดือนก่อน

      ​@@AdeogoSosanya-hh6uothe first thing is code. probably doesn't change the time per execution much, helps to understand what happens

  • @marklonergan3898
    @marklonergan3898 4 หลายเดือนก่อน +19

    "the sleep ensures the function isn't run too fast"
    Don't worry, by writing your code in python, it will never run too fast.

    • @yanantonio4016
      @yanantonio4016 2 หลายเดือนก่อน +2

      if you write in JavaScript, it wouldn't run faster either 🤷

    • @ambrishdubey2241
      @ambrishdubey2241 2 หลายเดือนก่อน

      ​@@yanantonio4016you seem to be experienced in js, can you tell me which projects are necessary in js to make us understand it even more ?

  • @m3hdim3hdi
    @m3hdim3hdi 2 หลายเดือนก่อน +3

    you can do it in 1 line of code
    def f(score):
    return 'F' if score < 60 else chr((100 - score) // 10 + ord('A'))

  • @RemoteAccessGG
    @RemoteAccessGG 5 หลายเดือนก่อน +17

    If we aren’t using quantum optimisations, most efficient way is by making a dict that contains the number and grade. You can make separate function for doing distance calculation with NUMPY.

    • @soupisfornoobs4081
      @soupisfornoobs4081 5 หลายเดือนก่อน

      Looks to me like the most efficient way would be a hash map

    • @schwingedeshaehers
      @schwingedeshaehers 4 หลายเดือนก่อน

      are you sure about that in Python? especially thinking about storage as well

    • @RemoteAccessGG
      @RemoteAccessGG 4 หลายเดือนก่อน

      @@schwingedeshaehers you also can spend a little of your time making a dict / hashmap with ranges, but I prefer flexibility.

    • @schwingedeshaehers
      @schwingedeshaehers 4 หลายเดือนก่อน

      @@RemoteAccessGG from my own experience dicts in Python need much memory (tried soke python scripts on microcontroller, circuit Python), and depending in the direction it can be much better to use tuples (with a[number-lowestnumber]), or if the input is a char, get the number of it, subtract to lowest possible numer, and use a tuple

  • @akshayrathod9557
    @akshayrathod9557 ปีที่แล้ว +43

    I am a complete noob but this guy explained so well I understood everything

    • @Hizashisam
      @Hizashisam ปีที่แล้ว +3

      Please refrain from described practice!!

    • @alfredogunbayo
      @alfredogunbayo 8 หลายเดือนก่อน

      @@Hizashisamwhat is described practice?

    • @gmilluh
      @gmilluh 7 หลายเดือนก่อน

      @@alfredogunbayoif you’re here you already know, heed the warning 🤲🏾

  • @OneWeirdDude
    @OneWeirdDude 4 หลายเดือนก่อน +9

    Never thought I'd see a Python comedian.

    • @MindBlowerWTF
      @MindBlowerWTF 3 หลายเดือนก่อน

      ☠️☠️☠️

  • @CreatorsExpress
    @CreatorsExpress ปีที่แล้ว +28

    I used this trick. My cto told me I get a raise!! Thanks man!!

    • @originalbinaryhustler3876
      @originalbinaryhustler3876 11 หลายเดือนก่อน

      for real??

    • @CreatorsExpress
      @CreatorsExpress 11 หลายเดือนก่อน +2

      @@originalbinaryhustler3876 no lol

    • @Krixwell
      @Krixwell 4 หลายเดือนก่อน +2

      A raise as in "raise an error", perhaps

  • @EvilCherry3
    @EvilCherry3 ปีที่แล้ว +32

    Thanks I’ll definitely use these tricks on the code that my boss told me to improve. Can’t wait to see his satisfaction tomorrow ! :)

    • @robmulla
      @robmulla  ปีที่แล้ว +13

      You might as well buy something expensive on amazon tonight because when your boss sees these implemented he will immedately give you a raise.

    • @greyshopleskin2315
      @greyshopleskin2315 ปีที่แล้ว +2

      @@robmulla He should buy an expensive house using a loan

  • @Khortax
    @Khortax 4 หลายเดือนก่อน +4

    me when I print 721 shit emojis to a client

  • @josephlyons3393
    @josephlyons3393 2 หลายเดือนก่อน

    The second the video popped up, I went “ehhh, needs some guard clauses” 🤣

  • @vasudevmenon2496
    @vasudevmenon2496 หลายเดือนก่อน

    Refactoring it further to remove below 90% scores and ran the code it on Google tensor and Intel CPU. Core temps reached 110C with 0% battery remaining in an instant

  • @lighty5738
    @lighty5738 2 หลายเดือนก่อน

    Every cell in my body feels pain watching this 😂

  • @user-yr1uq1qe6y
    @user-yr1uq1qe6y 7 หลายเดือนก่อน +1

    Now I’m questioning everything you ever told me in the data science videos!

  • @MurderByProxy
    @MurderByProxy 5 หลายเดือนก่อน +1

    sums up every python programmer out there

  • @adi96adi
    @adi96adi 3 หลายเดือนก่อน

    I paused the video midway for about a minute trying to guess what the optimization would be

  • @mrzorak4532
    @mrzorak4532 2 หลายเดือนก่อน +1

    This guy taught me the basics of data science in Python. This should be true.

  • @D_To_The_J
    @D_To_The_J 5 หลายเดือนก่อน +1

    You can also use pandas to train a ML model then use the continuem transfunctioner to egg out 10% more speed.

  • @Mr.Nichols
    @Mr.Nichols 11 หลายเดือนก่อน +2

    Me: *checks today's date halfway through the video*

    • @robmulla
      @robmulla  11 หลายเดือนก่อน +1

      Haha. You picked up on it quick.

  • @ShonenBallzy
    @ShonenBallzy 10 วันที่ผ่านมา +1

    im curious on how he says it with a straight face 😂

  • @sevenway1217
    @sevenway1217 11 หลายเดือนก่อน +15

    You put 50 and it returned C instead of F

    • @robmulla
      @robmulla  11 หลายเดือนก่อน +3

      bad edit

    • @abail7010
      @abail7010 5 หลายเดือนก่อน +5

      This is because of speed optimization!

    • @HT79
      @HT79 5 หลายเดือนก่อน +8

      This code kicked in an advanced AI which derived that the student's score was low due to external factors like war and global warming, so it took the discretion to assign them a more appropriate grade.

    • @jhgvvetyjj6589
      @jhgvvetyjj6589 4 หลายเดือนก่อน +1

      Branches aren’t thread safe so we need to import antigravity to load the proper GPU libraries that convert every branch to thread safe code

  • @ScienceMinisterZero
    @ScienceMinisterZero 6 หลายเดือนก่อน +2

    This is a whole new genre of content.

    • @robmulla
      @robmulla  6 หลายเดือนก่อน

      Hopefully you enjoyed.

  • @progamming242
    @progamming242 2 หลายเดือนก่อน

    Yeah this is super
    Important. one time I only used 720 in production and all of TH-cam crashed

  • @kaykay395w
    @kaykay395w 9 หลายเดือนก่อน +1

    Rob Mulla has been and is still such a help throughout my Data Science journey that for a sec or two I considered even this advice legit.

  • @Cool-dude1376
    @Cool-dude1376 11 หลายเดือนก่อน +3

    Holy crap I’m a lil baby who uses scratch and this is mighty similar, just in letters, I might to migrate to Python

  • @michaelmueller9635
    @michaelmueller9635 10 หลายเดือนก่อน

    I did put it straight into production code. Thx for the advice, bro.

  • @kipchickensout
    @kipchickensout 3 หลายเดือนก่อน

    this feels just as useful as the average python tips video lol

  • @rutvikrana512
    @rutvikrana512 10 หลายเดือนก่อน +3

    Most pythonic way. 😎
    calculate_grades = lambda x: ['D', 'C', 'B', 'A', 'A', 'F'] [v if ((v:=int(x/10)-6)>=0) else 5]

  • @user-kw2br1up2r
    @user-kw2br1up2r 2 หลายเดือนก่อน

    I add sleeps everywhere in my code, that way, when people ask me to optimize it, I turn a few off and people think I'm brilliant.
    Nice trick with the emoji's though, adding the memory addressing binary overflow to accelerate the processor. Only works with the exact number of poop emojis.

  • @tobi-b
    @tobi-b 5 หลายเดือนก่อน +1

    I know this is a meme video, but the most "efficient" way would probably be to have an array or a string containing the grades and then do some math on the score to get the index matching the grade

  • @LanceBryantGrigg
    @LanceBryantGrigg 3 หลายเดือนก่อน

    Excellent software learnings going on here.

  • @SchvarczFranco
    @SchvarczFranco 6 หลายเดือนก่อน +1

    It seems very accurate according to some coders of legacy codes I have faced.

  • @mikulcek
    @mikulcek ปีที่แล้ว +1

    By testing I found magic happens when you keep squaring icon count for each if statement, GPU goes into superpower mode.

  • @hardikjoshi8111
    @hardikjoshi8111 8 หลายเดือนก่อน +2

    Published on arXiv

  • @justinliu7788
    @justinliu7788 11 หลายเดือนก่อน +4

    me making a list and indexing into it

  • @jarodlokrantz8655
    @jarodlokrantz8655 5 หลายเดือนก่อน +5

    It's not going to speed up your 5 lines of Python to put them on a GPU lol, in fact the overhead alone will be killer, but in addition, you're doing multiple conditionally branched instructions on one data point which is the exact opposite of what GPUs are good at.
    Edit: Lmao I'm an idiot he's being sarcastic. My bad y'all. Don't be like me.

    • @justinwatson1510
      @justinwatson1510 4 หลายเดือนก่อน +1

      I knew this would be fun to read because it was edited, and I wasn't wrong. It happens to everyone at some point in their lives, and I respect the fact that you left the comment up instead of deleting it.

  • @yaweli2968
    @yaweli2968 4 หลายเดือนก่อน

    Coincidentally, I am popping and watching this simultaneously. What a life!

  • @evinroen6401
    @evinroen6401 5 หลายเดือนก่อน +4

    How could you not mention the hidden +0.01% optimization by adding semicolons

  • @dlizard04
    @dlizard04 7 หลายเดือนก่อน +3

    This is one of the most helpful python shorts I've seen. Thank you sir.

  • @markhaus
    @markhaus 4 หลายเดือนก่อน

    If you use the 👺 emoji this memory location gets passed to the quantum processor and finishes with every grade possible almost instantly

  • @worgenzwithm14z
    @worgenzwithm14z 4 หลายเดือนก่อน

    Crazy what languages that don't have an effects system can do in the middle of a seemingly harmless function

  • @mr.unknown6179
    @mr.unknown6179 5 หลายเดือนก่อน +2

    My Try:
    def grade(score):
    score = score//10
    match score:
    case 10:
    return 'A'
    case 9:
    return 'A'
    case 8:
    return 'B'
    case 7:
    return 'C'
    case 6:
    return 'D'
    case _:
    return 'F'

    • @miudi9535
      @miudi9535 5 หลายเดือนก่อน

      For simple cases like this, if-elsif statements are faster

    • @HT79
      @HT79 5 หลายเดือนก่อน

      Jokes apart, don't do this. Pattern matching in python is different to switch cases in other languages. Since this is not the right use case, it might lead to other issues like performance and maintainability.

  • @stephen2282
    @stephen2282 ปีที่แล้ว

    for a second I had to check if it was still april

  • @Michael.storen
    @Michael.storen 5 หลายเดือนก่อน +1

    hi, i added this to my github last week. do you think this project is enough for senior python developer? thank you

  • @yekhtiari
    @yekhtiari 4 หลายเดือนก่อน

    That is why the boss thinks we are popping in the code.

  • @SR-ti6jj
    @SR-ti6jj 10 หลายเดือนก่อน

    Thanks! Uing this to optimize the performance of this web server I'm running on a headless VM!

  • @groolzerman223
    @groolzerman223 5 หลายเดือนก่อน

    What program are you using to code and i'm very curious thank you ❤

  • @SuperSumittanwar
    @SuperSumittanwar 3 หลายเดือนก่อน

    I laughed when you added poopomozi even when i wanted to praise :)

  • @aarunpm
    @aarunpm 11 หลายเดือนก่อน

    I was facing gpu driver issues in out on PREM production server with poppy code now it’s 🚀 , just make sure you maintain the 721 hyper parameter for perfect tuning

  • @themannyzaur
    @themannyzaur 5 หลายเดือนก่อน

    Good game my dude
    You had me ngl 😂😂

  • @astrovicis
    @astrovicis 5 หลายเดือนก่อน +1

    score_map = { range(9, 11): ‘A’, 8: ‘B’, 7: ‘C’, 6: ‘D’, range(0, 6): ‘F’ }
    return score_map[score // 10]

  • @vacucumber_enjoyer
    @vacucumber_enjoyer 8 หลายเดือนก่อน

    Create look up table, switch score by 50 and then divide the changed score by 10, then use the output from the operations as your index. 0 means F, 1 means D, 2 means E, 3 means F... Pretty simple solution.

  • @lemonpug6582
    @lemonpug6582 4 หลายเดือนก่อน

    “Make it more efficient by making it slower” I was so fucking confused for a good 20 seconds trying to understand why you were just adding a time buffer lmao

  • @Ajaja-ov5wt
    @Ajaja-ov5wt 4 หลายเดือนก่อน +1

    I want my performance to increase by 10k % pop emojis rule

  • @DelightfulPager-ro4nw
    @DelightfulPager-ro4nw 5 หลายเดือนก่อน +1

    This guy a true Python programmer 🙂

  • @steampunkWizardStudios
    @steampunkWizardStudios หลายเดือนก่อน +1

    JAVASCRIPT SWITCH STATEMENT

  • @kendlemintjed7571
    @kendlemintjed7571 5 หลายเดือนก่อน

    i was very confused until i read the title 😂

  • @matthewread9001
    @matthewread9001 5 หลายเดือนก่อน

    One of the first things my CST professors taught with functions was to not early return. And I’m like “why”

  • @davidlee588
    @davidlee588 3 หลายเดือนก่อน

    U got me but I don’t like you mess up with my brain 😂

  • @bluelinden
    @bluelinden 2 หลายเดือนก่อน

    real python code written by real developers to give python any sense of runtime efficiency:

  • @sweealamak628
    @sweealamak628 7 หลายเดือนก่อน

    Yes. This is a problem I'm facing where my for loop runs too quickly when calling a function. Ended up executing the final instance only. Had to add sleep(0.1) just to give Python a breather. I think this is the downside of interpreting with Python, I never had timing issues compiling in C++.

  • @sorin.n
    @sorin.n 5 หลายเดือนก่อน

    Mooom'! The computer has dihareea! 😂

  • @thoughts_empty
    @thoughts_empty 8 หลายเดือนก่อน

    You should have added that time.sleep function as a decorator and ad that decoration to each if statement.
    *Just to make it easier to read.*
    Where there is a never nester, there is also a never decorator...
    Idk If I was right, I'm just your average never decorator

  • @rohanaggarwal8718
    @rohanaggarwal8718 7 หลายเดือนก่อน

    what ide is that, cuz it looks sick (is it vscode jupyter?)

  • @nico32433
    @nico32433 6 หลายเดือนก่อน

    If you add
    "while True:
    pass"
    at the beginning of you function, it will actually charge up your CPU so afterwards the code runs in a fraction of a second

  • @korigamik
    @korigamik 11 หลายเดือนก่อน

    What editor are you using?

  • @ShiloBuff
    @ShiloBuff 5 หลายเดือนก่อน

    You are trolli... wait 10 thousand percent? I'm sold!

  • @Edg30fd3w0r1d
    @Edg30fd3w0r1d 3 หลายเดือนก่อน

    I NEVER EVER EVER WANT TO SEE THAT FIRST EXAMPLE EVER AGAIN WTF

  • @PaulGrossmanTheDarkArtsWizard
    @PaulGrossmanTheDarkArtsWizard 5 หลายเดือนก่อน

    I am following you only because this was so plausible and made me laugh.

  • @COALROCK8642
    @COALROCK8642 5 หลายเดือนก่อน

    IDK poop emoji; but I too learned that sleep timers show speed or time stepping of your code.

  • @slicer2938
    @slicer2938 5 หลายเดือนก่อน +1

    says to optimise code*
    purposefully slows it down*

  • @murphygreen8484
    @murphygreen8484 3 หลายเดือนก่อน

    Would a switch case be even faster?

  • @ivanoviich5847
    @ivanoviich5847 5 หลายเดือนก่อน

    Lol I should've read the title before watching, well done

  • @viclim289
    @viclim289 2 หลายเดือนก่อน

    I mean ... April Fool's day is just around the corner

  • @PatriceFERLET
    @PatriceFERLET 3 หลายเดือนก่อน

    Now Python has got "match" block. It's like switch case in others languages... Use it.

  • @Quo777
    @Quo777 4 หลายเดือนก่อน

    That’s perfect for cold nights!

  • @duckbilldaniel
    @duckbilldaniel 4 หลายเดือนก่อน

    And if you're on python 3.11, you can use case blocks instead. Please note you have to print 420 💩's to compensate, or else it generates error 0x45 (error number 69 for non hex readers)

  • @h2obeachboy143
    @h2obeachboy143 ปีที่แล้ว +1

    Turtle activated lol

  • @WeirdDuck781
    @WeirdDuck781 5 หลายเดือนก่อน

    If it wasnt for the poop emoji this shit mightve even go past and around most junior IT/devs ive met ngl

  • @kipchickensout
    @kipchickensout 3 หลายเดือนก่อน

    how about
    def calculate_grade(score):
    return 'F' if score < 60 else chr(max(74 - score // 10, 65))

  • @danielmajer1648
    @danielmajer1648 5 หลายเดือนก่อน

    I'm more concerned about the returns on the same line with the if staments.

  • @moreshwarmeshram3175
    @moreshwarmeshram3175 10 หลายเดือนก่อน

    You can also use threads

  • @originalbinaryhustler3876
    @originalbinaryhustler3876 11 หลายเดือนก่อน +1

    dude you are funny af!!!
    I like the refactoring though!

    • @robmulla
      @robmulla  11 หลายเดือนก่อน +1

      I appreciate it! What's so funny though :D

    • @originalbinaryhustler3876
      @originalbinaryhustler3876 11 หลายเดือนก่อน

      @@robmulla 😇😇

    • @originalbinaryhustler3876
      @originalbinaryhustler3876 11 หลายเดือนก่อน

      @@robmulla you actually had me going for a while! i love it 👊🏻👊🏻

  • @priyanshusharma751
    @priyanshusharma751 5 หลายเดือนก่อน

    why are we making is slower? i didn't get the idea of adding 721 poop emoji.

  • @XoxYoyZoz
    @XoxYoyZoz 7 หลายเดือนก่อน

    I tho he gonna use a hashmap but he rickrolled me instead 💀

  • @noadsplease2737
    @noadsplease2737 9 หลายเดือนก่อน

    Talk about (ir)regular expression(s)

  • @raxitgohel2999
    @raxitgohel2999 5 หลายเดือนก่อน

    169 🍑's works as well. Apparently it raises CPU temperature which in turn makes GPU do the work.

  • @renanwilliamprado5380
    @renanwilliamprado5380 4 หลายเดือนก่อน

    A good alternative to give a score in an optimized way is to use a binary search. So, when you run a score x, you divide 100 by two parts. If it is lower than 60, you set F, if it is above, you can test if it is below 80 or above 80. If below, you can test whether it is below 70 or above 70. If below, you give D, if above you give C. On the other hand, if above 80, you can test whether it is below 90 or above 90. If below, you give B, id above A. This way, since the scores usually form a normal distribution, you are testing fewer if statements in the mean.
    P.S.: this is truly optimized. Not a joke. Hahaha

  • @PDsChannel0112
    @PDsChannel0112 10 หลายเดือนก่อน +1

    Can we use any emoji other than the poop emoji?

  • @aritramukherjee
    @aritramukherjee 2 หลายเดือนก่อน

    I went through the video faster by watching only first 15 sec.😂

  • @oscarthethird25
    @oscarthethird25 7 หลายเดือนก่อน

    What IDE are you using?

  • @michealkinney6205
    @michealkinney6205 6 หลายเดือนก่อน

    This is a nuanced hack that also works in C++