Posts

Showing posts with the label Programming

Understanding why Go/Rust >> Python/Nodejs for CPU-bound tasks!

Image
The Setup Picture this: you've got a CPU-intensive task—computing the sum of squares for 50 million numbers. You fire up Python with 4 threads, expecting to see your 4-core machine flex its muscles. But something's wrong. Your CPU usage hovers around 25%, and the program takes just as long (or longer) than if you'd used a single thread. What's happening? You've just met Python's Global Interpreter Lock (GIL), and it's not playing nice with your parallel dreams. The Experiment To understand this phenomenon, I built a simple benchmark: compute sum(i*i for i in range(N)) across multiple workers. This is pure CPU-bound work—no I/O, no waiting, just raw computation. The same task, implemented in three languages, tells a revealing story. Python (threads) : The GIL prevents multiple threads from executing Python bytecode simultaneously. Even with 4 threads, your program will mostly use 1 CPU core. You...

Property Wrapper - Simplified!

Introduction: There have been just so much fuzz around the Property Wrappers. Almost all the recent addition(@State, @Published, @Binding, @BindableObject, @ObservedObject, @EnvironmentObject, @Environment) to the SwiftUI framework is just based upon this single feature that was introduced in Swift 5.1 called ‘Property Wrappers’ There are just so many articles already written on Property Wrappers and some of them are just really great. I’m writing this piece not because I also wanted to write about it and join the bandwagon but because not everyone understands a topic written in a certain way.  Just a different mix of words or with a different set of contextual examples, basically the point is that not everyone likes Vanilla ice cream and the majority of people prefer flavors, so please don’t consider this article as a redundant one and do give it a chance to take it up as a different flavor. Btw, mine is chocolate, what’s yours? ;) Background: From Apple’s engine...