0

Scenario

I am working on a web application that handles financial transactions, and my code will need to be reusable for everything from consumer carts to manufacturer/distributor shipments. The project uses Laravel in a fairly typical LAMP environment.

I can use PHP's BCMath functions or MySQL queries to handle math operations, but the Eloquent ORM tends to create a lot of queries and db transactions, so I am unsure which will be better. I will need to do addition, subtraction, multiplication, and division with precision up to a the equivalent of a MySQL DECIMAL(10,4).

Question 1: performance

Which will have better performance for precision maths: MySQL queries or BCMath? The answer should include considerations for network overhead. MySQL is running on a Rackspace 8GB standard instance (8GB ram, 4 vCPUs, 600 Mbps, 320GB SSD); the PHP server is running on a Rackspace 2GB standard instance (2GB ram, 2 vCPUs, 240 Mbps, 80GB SSD). Server setup is adaptable, and there is a high likelihood of moving to Azure or AWS before or just after launch. The main reason that the MySQL server has better specs is that we were doing some big data analysis (multiple worker servers, 1 db) last year and still have large storage requirements.

Question 2: philosophy

If one is better than the other, does it make sense to worry about optimization during such an early stage of development (core functionality is still lacking), or is it better to just use whatever is convenient and optimize later?

  • Related: Is it always wrong to optimize before profiling? – user40980 Jun 25 '15 at 19:13
  • Sounds like your actual question is BCMath vs your ORM, not MySQL. – GrandmasterB Jun 25 '15 at 19:20
  • MichaelT: sort of, but not quite. This is a matter of "write sloppy first, optimize later" vs "write slightly optimized code now". – Jonathan Voss Jun 25 '15 at 19:28
  • "Write good code always, optimize when necessary" – user40980 Jun 25 '15 at 19:28
  • GrandmasterB: it is both. I can perform raw database queries within the ORM and can also optimize/modify the way it handles transactions, so I am more interested in MySQL vs BCMath. – Jonathan Voss Jun 25 '15 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.