basarat / basarat/algorithms

Idiomatic Bubble Sort Performance

Open
#3 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
303
Forks
63
PR merge metrics
No merged PRs in 30d

Description

@Basarat: I created arrays of 10K and 50K random integers. I sorted the same array in nodejs using both bubble sort examples. The idiomatic example performs slower that the basic sort example. Is that expected?

```
##############################################
# #
***** bubble sort *****
# #
##############################################
bubbleSortProcessing-[10000]: 4758.006ms
earlyTerminationBubbleSortProcessing-[10000]: 4994.364ms

[nodemon] clean exit - waiting for changes before restart
[nodemon] restarting due to changes...
[nodemon] starting `node ./index.js`

##############################################
# #
***** bubble sort *****
# #
##############################################
bubbleSortProcessing-[50000]: 119734.447ms
earlyTerminationBubbleSortProcessing-[50000]: 125780.788ms

[nodemon] clean exit - waiting for changes before restart

```

I did notice a performance gain with Idiomatic sort using smaller data sets.

```
##############################################
# #
***** bubble sort *****
# #
##############################################
bubbleSortProcessing-[500]: 16.692ms
earlyTerminationBubbleSortProcessing-[500]: 12.605ms
[nodemon] clean exit - waiting for changes before restart

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.