Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: HoBzY on October 09, 2022, 04:40:16 PM



Title: What is the best language to write a miner in?
Post by: HoBzY on October 09, 2022, 04:40:16 PM
What is the best language to write a miner in?


Title: Re: What is the best language to write a miner in?
Post by: jackg on October 09, 2022, 05:03:57 PM
The one you're most comfortable writing with. Most of the time the language you use doesn't matter, most systems have APIs that allow you to call other programs in other languages too (like how python's os module lets you run command line tasks).

If you're fairly new to programming there's ups and downs to using langiages that are statically typed (like c based languages and java) and ones that are dynamically typed (like python).

If you find you're very comfortable (/enjoying) programming one specific language, whatever it is, write it in that. If you don't care, you could always try both types.


Title: Re: What is the best language to write a miner in?
Post by: n0nce on October 09, 2022, 05:12:11 PM
What is the best language to write a miner in?
Why would you want to write your own miner? There is open-source CPU, GPU and ASIC miner software for almost everything (and that you can adapt to your hardware if unsupported).

Recent topics about Bitcoin mining setup on Testnet.
bfgminer (CPU, GPU): https://bitcointalk.org/index.php?topic=5415861.0
cgminer (ASIC): https://bitcointalk.org/index.php?topic=5415335.0


Title: Re: What is the best language to write a miner in?
Post by: HoBzY on October 09, 2022, 05:27:25 PM
The one you're most comfortable writing with. Most of the time the language you use doesn't matter, most systems have APIs that allow you to call other programs in other languages too (like how python's os module lets you run command line tasks).

If you're fairly new to programming there's ups and downs to using langiages that are statically typed (like c based languages and java) and ones that are dynamically typed (like python).

If you find you're very comfortable (/enjoying) programming one specific language, whatever it is, write it in that. If you don't care, you could always try both types.


What is the best language for hash generation speed? Is it worth learning C++?


Title: Re: What is the best language to write a miner in?
Post by: NotATether on October 09, 2022, 05:31:07 PM
What is the best language for hash generation speed? Is it worth learning C++?

Assuming mining difficulty is low enough for CPU mining. C++ for a command-line frontend is OK, but the mining library itself must be written in pure C (no STL constructs) or even better in assembly, for maximum performance.

I'd stay away from all other languages including Rust.


Title: Re: What is the best language to write a miner in?
Post by: DannyHamilton on October 09, 2022, 06:45:30 PM
What is the best language for hash generation speed? Is it worth learning C++?

It depends on your skills with the language.

It is possible to write some VERY inefficient and slow code in C, and some very fast and efficient code in other languages.  Choosing a language without having a good understanding of computing principles isn't going to get you the best possible results.


Title: Re: What is the best language to write a miner in?
Post by: n0nce on October 09, 2022, 06:47:17 PM
What is the best language for hash generation speed? Is it worth learning C++?

It depends on your skills with the language.

It is possible to write some VERY inefficient and slow code in C, and some very fast and efficient code in other languages.  Choosing a language without having a good understanding of computing principles isn't going to get you the best possible results.
I believe if he had such understanding though, he wouldn't ask this question. So maybe best to use what's already available (if it's about performance), as I described above. Or use any language they like, if it's about education / learning, because performance doesn't matter.

We really need more information about the actual end goal, otherwise it's another https://xyproblem.info/.


Title: Re: What is the best language to write a miner in?
Post by: serhack on October 09, 2022, 07:45:00 PM
What is the best language to write a miner in?

If you're really expert and know what you're doing, for sure C is the most powerful programming language that allows you to think as a "machine". Assembly would be more performant but good luck not loosing your mind :D

For people suggesting any OOP-based language or GC-based language, you're going to waste some helpful CPU burst on checking pointers, and allocations. C is a nightmare for pointers but it can allow you to write very efficient program without too much efforts. Unfortunately you need to master pointers management and you need to carefully think about the instruction cycle (fetch, decode, execute), pipelines and much more to waste CPU burst as few as possible.


Title: Re: What is the best language to write a miner in?
Post by: pooya87 on October 10, 2022, 04:35:13 AM
What is the best language for hash generation speed? Is it worth learning C++?
If you don't already know the language you will not be able to write the most efficient code needed for mining in that language that you would be learning the basics for! Optimization is a complicated topic that you can start on at an advanced level.
Try using the existing code that other experts have already written.


Title: Re: What is the best language to write a miner in?
Post by: HoBzY on October 10, 2022, 06:49:54 AM
What is the best language to write a miner in?

If you're really expert and know what you're doing, for sure C is the most powerful programming language that allows you to think as a "machine". Assembly would be more performant but good luck not loosing your mind :D

For people suggesting any OOP-based language or GC-based language, you're going to waste some helpful CPU burst on checking pointers, and allocations. C is a nightmare for pointers but it can allow you to write very efficient program without too much efforts. Unfortunately you need to master pointers management and you need to carefully think about the instruction cycle (fetch, decode, execute), pipelines and much more to waste CPU burst as few as possible.

I think I can understand it because I already know html/css/js/php/mysql web languages ​​and know python/c# and for learning blockchain mining I used python for test.



What is the best language for hash generation speed? Is it worth learning C++?
If you don't already know the language you will not be able to write the most efficient code needed for mining in that language that you would be learning the basics for! Optimization is a complicated topic that you can start on at an advanced level.
Try using the existing code that other experts have already written.
Can I have a couple of links to them? C is best learned by example.

[moderator's note: consecutive posts merged]


Title: Re: What is the best language to write a miner in?
Post by: tromp on October 10, 2022, 11:46:32 AM
What is the best language to write a miner in?

Something like VHDL or Verilog [1].

[1] https://en.wikipedia.org/wiki/Hardware_description_language


Title: Re: What is the best language to write a miner in?
Post by: pooya87 on October 10, 2022, 01:38:25 PM
~
Can I have a couple of links to them? C is best learned by example.
@n0nce already posted two of them, both written in C:
https://github.com/luke-jr/bfgminer
https://github.com/cmmodtools/cgminer


Title: Re: What is the best language to write a miner in?
Post by: serhack on October 10, 2022, 03:01:36 PM
What is the best language to write a miner in?

If you're really expert and know what you're doing, for sure C is the most powerful programming language that allows you to think as a "machine". Assembly would be more performant but good luck not loosing your mind :D

For people suggesting any OOP-based language or GC-based language, you're going to waste some helpful CPU burst on checking pointers, and allocations. C is a nightmare for pointers but it can allow you to write very efficient program without too much efforts. Unfortunately you need to master pointers management and you need to carefully think about the instruction cycle (fetch, decode, execute), pipelines and much more to waste CPU burst as few as possible.

I think I can understand it because I already know html/css/js/php/mysql web languages ​​and know python/c# and for learning blockchain mining I used python for test.

Yes, you might understand it without too much effort but the problem is optimizing that.


Title: Re: What is the best language to write a miner in?
Post by: n0nce on October 10, 2022, 07:43:57 PM
I think I can understand it because I already know html/css/js/php/mysql web languages ​​and know python/c# and for learning blockchain mining I used python for test.
Oh dear. Web languages, Python and C# won't help you at all when trying to write highly optimized low-level code.

Anyhow, could you answer what your actual goal is in the first place? Is it just a coding exercise? If so, the answer is: 'The best language is the one you're comfortable with and that is fun to write'.
If you want to develop something that competes with existing software, maybe just fork what already exists and optimize it further.
If you want to use it for Bitcoin mining, don't even bother with programming languages and go for FPGA or ASIC design, which is a whole different beast; you'd be looking at learning and understanding chip design, then implement it in VHDL or Verilog, as tromp suggested.


Title: Re: What is the best language to write a miner in?
Post by: Skot on October 12, 2022, 08:43:56 PM
If you want to see how someone else did it in python, check this; https://github.com/ricmoo/nightminer

if you're trying to go soup to nuts you'll need to setup a stratum proxy to connect to your bitcoin node. I found that bfgminer (mentioned earlier) or ckpool (https://bitbucket.org/ckolivas/ckpool/src/master/) worked for this. 


Title: Re: What is the best language to write a miner in?
Post by: Artem Sereda on November 10, 2022, 12:37:14 PM
The one you're most comfortable writing with. Most of the time the language you use doesn't matter, most systems have APIs that allow you to call other programs in other languages too (like how python's os module lets you run command line tasks).

If you're fairly new to programming there's ups and downs to using langiages that are statically typed (like c based languages and java) and ones that are dynamically typed (like python).

If you find you're very comfortable (/enjoying) programming one specific language, whatever it is, write it in that. If you don't care, you could always try both types.


What is the best language for hash generation speed? Is it worth learning C++?


As already mentioned here, it all depends on your skills in this language. Python was recommended here before. I would still prefer this language. It makes it easier to manipulate data. And it's easier to learn.