# Stupid text formatting performance question

**URL:** <https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433>\
**Category:** Technical Discussion\
**Created:** [May 12, 2022, 9:47pm UTC](https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433 "2022-05-12T21:47:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashinnv](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/ashinnv/32/10887_2.png) [@ashinnv](https://forum.golangbridge.org/u/ashinnv)\
**Post date:** [May 12, 2022, 9:47pm UTC](https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433/1 "2022-05-12T21:47:07Z")

</div>

Is there any real performance difference between doing  
`myStr := strconv.Itoa(42);fmt.Println(myStr)`  
and  
`fmt.Println(fmt.Sprintf("%d",42)`? That’s it. Simple, stupid question.

---

<div class="post-metadata">

**Author:** ![G4143](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@G4143](https://forum.golangbridge.org/u/G4143)\
**Post date:** [May 13, 2022, 7:19am UTC](https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433/2 "2022-05-13T07:19:23Z")

</div>

I’d guess that Sprintf is slower because it has to parse the format string("%d").

---

<div class="post-metadata">

**Author:** ![GonzaSaya](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/gonzasaya/32/4535_2.png) [@GonzaSaya](https://forum.golangbridge.org/u/GonzaSaya)\
**Post date:** [May 23, 2022, 12:54pm UTC](https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433/3 "2022-05-23T12:54:44Z")

</div>

Here is a benchmark test about your question:

> **[Performance test of several methods based on go int to string - Develop Paper](https://developpaper.com/performance-test-of-several-methods-based-on-go-int-to-string/)**
>
> There are at least three ways to convert int to string in go language: fmt.Sprintf("%d",n) strconv.Itoa(n) strconv.FormatInt(n,10) The following is a simple test of the performance of these three methods: package gotest import ( "fmt" "strconv"...

Anyway you can benchmark your code with golang 😃

---

<div class="post-metadata">

**Author:** ![ashinnv](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/ashinnv/32/10887_2.png) [@ashinnv](https://forum.golangbridge.org/u/ashinnv)\
**Post date:** [June 1, 2022, 3:12am UTC](https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433/4 "2022-06-01T03:12:14Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [August 30, 2022, 3:12am UTC](https://forum.golangbridge.org/t/stupid-text-formatting-performance-question/27433/5 "2022-08-30T03:12:30Z")

</div>

Closed on August 30, 2022, 3:12am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
