Code For the Environment

Our packages would help you calculate the total carbon emission of running your code and then evaluate the code to improve and reduce the carbon emission of the code!

billing

How it works?, check out the methodology!

With our tool , you can monitor the carbon emission of your application and optimize your code to reduce it!

Get Started
star

Understand

Gain a better understanding of their impact and how emissions are distributed across areas of the coding environment

star

Share

Share that understanding with customers, stakeholders and business partners

star

Optimize

Use this shared understanding to take action and empower customers and partners to reduce their own emissions.

Calculate!

● Install our python package using the following command

pip install codearth

● Import codearth into your python module

● Wrap your code with the following functions

● Enter the output of the code in the CodeForEarth Calculator

● Now head over to our calculator and enter your values!

Calculator

Optimize!

There are two ways in which we can optimize the code

Machine-independent – In this, the compiler transforms a part of the intermediate code that does not involve any CPU registers and/or absolute memory locations. e.g, 3-address code.


Local Optimization – The optimization which is performed within the block(sequence of consecutive statements) is local optimization e, g. If-Else, switch-case, conditional statements and loops such as Do-While, For, and repeat-until, etc.

We follow the PEEPHOLE OPTIMIZATION technique of compiler design!

Perform the following optimizations on your code to reduce the resources it consumes

Constant Propagation: : If the value of a variable is a constant, then replace the variable with the constant. The variable may not always be a constant.

a = 30
b = 20 - a /2
c = b * ( 30 / a + 2 ) - a

TO

a = 30
b = 20 - 30/2
c = b * ( 30 / 30 + 2) - 30


Unreachable Code Elimination: : First, Control Flow Graph should be constructed. The block which does not have an incoming edge is an Unreachable code block. After constant propagation and constant folding, the unreachable branches can be eliminated.

int num;
num=10;
print "CodeForEarth"
return 0;
print num #unreachable code

TO

int num;
num=10;
Print "CodeForEarth Optimized!";
return 0;


Dead Code Elimination: A variable is said to be dead if it is never used after its last definition. In order to find the dead variables, a data flow analysis should be done.

c = a * b
x = a
till
d = a * b + 4

TO

c = a * b
till
d = a * b + 4


Multiplication and division by power of 2 : Use left shift() for multiplication and right shift() for division. The bit operations will be much faster than multiplication and division operations.For simple operations, the compiler may automatically optimize the code but in case of complex expressions it is always advised to use bit operations.

a=a*16

TO

a = a<<4

Perform the following optimizations on your Loops:

Loop Jamming: Two or more loops are combined in a single loop. It helps in reducing the compile time.

for(int k=0;k<10;k++)
{
x = k*2;
}
for(int k=0;k<10;k++)
{
y = k+3;
}

TO

for(int k=0;k<10;k++)
{
x = k*2;
y = k+3;
}


Loop Unrolling: Unroll small loops that can be manually converted to a code of few lines

for(int i=0;i<3;i++)
{
printf("Hello");
}

TO

printf("Hello");
printf("Hello");
printf("Hello");


Code Motion: Avoid evaluating expressions and performing calculations inside a loop and roll them outside the loop if they are constant and not dependent on the loop

a = 200;
while(a>0)
{
b = x + y;
if (a % b == 0)
printf(“%d”, a);
}

TO

a = 200;
b = x + y;
while(a>0)
{
if (a % b == 0)
printf(“%d”, a);
}


Reduce!

● Choose a green host!

Choose the correct cloud servers which source their energy from renewable sources like wind and water sources and have a less net carbon intensity. Green hosting providers are companies using data centers with high energy efficiency and commitment to using green energy sources.

● Plant trees to offset your carbon footprint and balance it

Trees are our best companions when it comes to lessening CO2 emissions. They assimilate CO2 and create oxygen for us to breathe. Other than, planting trees is additionally a way of giving back to the community where your company/business is based. A green-looking neighborhood/community is always a superb view.

● By making your code leaner

Lean code always reduces the size of the data that is transferred to and from the memory and the processor and thus optimizes the code for better power consumption. The reduction in power usage reduces the total carbon emission of the code!

billing

You can't manage what you don’t measure

CodeForEarth helps you provide a way to find the carbon emission of your application and also gives you suggestions on how to optimize your code for better results considering wide varieties of factors such as your location, your power usage and many more!

Optimize your code in few easy steps.

From data centers to transmission networks to the billions of connected devices that we hold in our hands, it is all consuming electricity, and in turn producing carbon emissions equal to or greater than the entire air travel industry.

Get Started
billing

Give code for earth a try right now !

Everything you need to contribute for the betterment of our environment while sitting in front of the computer

hoobank

Calculate and Optimize your Carbon emission!

Copyright Ⓒ 2022 CodeForEarth. All Rights Reserved.

social-media-1social-media-2social-media-3social-media-4