DEV Community

OpenSource for Webcrumbs

Posted on

7 1

Unlocked a new GPT functionality: performance calculations

So I was curious if using a super long hash would impact my apps performance.

Asked ChatGPT 4o:

1. What's the performance comparison between x and y?

In this example, x and y were:

const hash = crypto.createHash('sha256').update(message + code + (files ? files.map(f => f.buffer.toString('hex')).join('') : '') + uniqueValue).digest('hex');
Enter fullscreen mode Exit fullscreen mode
const hash = crypto.createHash('sha256').update(uniqueValue).digest('hex');
Enter fullscreen mode Exit fullscreen mode

Okay. It blabed a little bit. It even wrote the code so I could verify it. But I wanted an answer. So second and last iteration:

2. Can you run and let me know? Use fake data as input

And bum! Got my answer in a few seconds.

The performance comparison between the two methods is as follows:

Long Input Hash:
0.1235 seconds for 100,000 iterations

Short Input Hash:
0.1061 seconds for 100,000 iterations

As expected, the short input hash is slightly faster. The difference, while measurable, is relatively small. This indicates that if you are hashing a relatively small number of times, the performance impact will be minimal. However, if you need to optimize for the fastest possible hashing in a high-frequency context, using a short input value like a unique counter or timestamp is the better option. ​

Hope it helps!
Happy coding.

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry πŸ•’

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video