728x90

 

수행환경

  - Flask,  psycopg2

 

수행코드

@app.route('/adduser')
def add_user():
	pg_conn = psycopg2.connect(host=HostName, dbname=DatabaseName, user=DatabaseUser, password=DatabasePassword, port=DatabasePort);
	cursor = pg_conn.cursor();
	print( datetime.now() )
	for i in range(90000):
		email_value = str(i)+"love@speech.pe.kr"
		#print(type(email_value))
		cursor.execute("INSERT INTO users(email, enabled, is_changed) VALUES ( '" + email_value+ "', False, False )");
	
	print( datetime.now() )
	pg_conn.commit()
	print("Record(s) Inserted")
	pg_conn.close()
	return "SUCCESS"

 

 

수행결과. :: 90,000개의 데이터 처리 

2023-11-30 13:52:52.242111
2023-11-30 13:57:06.182638
Record(s) Inserted
192.168.50.50 - - [30/Nov/2023 13:57:06] "GET /adduser HTTP/1.1" 200 -
2023-11-30 13:57:29.635902
2023-11-30 13:57:30.011986
192.168.50.50 - - [30/Nov/2023 13:57:30] "GET /alluser HTTP/1.1" 200 -
2023-11-30 13:58:32.326976
2023-11-30 14:07:12.938968
Record(s) Deleted
192.168.50.50 - - [30/Nov/2023 14:07:12] "GET /deluser HTTP/1.1" 200 -

 

즉, 90,000개의 데이터를

추가할 때는 약 4분 14초가 소요되었고 

조회할 때는  0.5초가 소요되었고

삭제할 때는 약 8분 40초가 소요되었습니다.

728x90
반응형
728x90

수행 코드

arr=[40,60,70,50,10,20,30]

for i in range(1,len(arr)):
    for j in range(i, 0, -1):
        print("i 번째", i, ", j 인덱스 ", j )
        if arr[j-1] > arr[j]:
            arr[j], arr[j-1] = arr[j-1], arr[j]
        print("Inner Result: ", arr )
    print(">>Partial Result: ", arr )

print(">>>> Final Result ", arr )

 

 

수행 결과 화면

PS D:\PythonCode> python .\InsertionSorting.py
i 번째 1 , j 인덱스  1
Inner Result:  [40, 60, 70, 50, 10, 20, 30]
>>Partial Result:  [40, 60, 70, 50, 10, 20, 30]
i 번째 2 , j 인덱스  2
Inner Result:  [40, 60, 70, 50, 10, 20, 30]
i 번째 2 , j 인덱스  1
Inner Result:  [40, 60, 70, 50, 10, 20, 30]
>>Partial Result:  [40, 60, 70, 50, 10, 20, 30]
i 번째 3 , j 인덱스  3
Inner Result:  [40, 60, 50, 70, 10, 20, 30]
i 번째 3 , j 인덱스  2
Inner Result:  [40, 50, 60, 70, 10, 20, 30]
i 번째 3 , j 인덱스  1
Inner Result:  [40, 50, 60, 70, 10, 20, 30]
>>Partial Result:  [40, 50, 60, 70, 10, 20, 30]
i 번째 4 , j 인덱스  4
Inner Result:  [40, 50, 60, 10, 70, 20, 30]
i 번째 4 , j 인덱스  3
Inner Result:  [40, 50, 10, 60, 70, 20, 30]
i 번째 4 , j 인덱스  2
Inner Result:  [40, 10, 50, 60, 70, 20, 30]
i 번째 4 , j 인덱스  1
Inner Result:  [10, 40, 50, 60, 70, 20, 30]
>>Partial Result:  [10, 40, 50, 60, 70, 20, 30]
i 번째 5 , j 인덱스  5
Inner Result:  [10, 40, 50, 60, 20, 70, 30]
i 번째 5 , j 인덱스  4
Inner Result:  [10, 40, 50, 20, 60, 70, 30]
i 번째 5 , j 인덱스  3
Inner Result:  [10, 40, 20, 50, 60, 70, 30]
i 번째 5 , j 인덱스  2
Inner Result:  [10, 20, 40, 50, 60, 70, 30]
i 번째 5 , j 인덱스  1
Inner Result:  [10, 20, 40, 50, 60, 70, 30]
>>Partial Result:  [10, 20, 40, 50, 60, 70, 30]
i 번째 6 , j 인덱스  6
Inner Result:  [10, 20, 40, 50, 60, 30, 70]
i 번째 6 , j 인덱스  5
Inner Result:  [10, 20, 40, 50, 30, 60, 70]
i 번째 6 , j 인덱스  4
Inner Result:  [10, 20, 40, 30, 50, 60, 70]
i 번째 6 , j 인덱스  3
Inner Result:  [10, 20, 30, 40, 50, 60, 70]
i 번째 6 , j 인덱스  2
Inner Result:  [10, 20, 30, 40, 50, 60, 70]
i 번째 6 , j 인덱스  1
Inner Result:  [10, 20, 30, 40, 50, 60, 70]
>>Partial Result:  [10, 20, 30, 40, 50, 60, 70]
>>>> Final Result  [10, 20, 30, 40, 50, 60, 70]

 

 

수행결과 분석

728x90
반응형
728x90

수행 코드

arr = [40, 70, 60, 30, 10, 50]

# acending
for i in range( len(arr)-1, 0, -1):    # number of pairs.    
    for j in range(i):
        print( "i=", i, "j=", j )
        if arr[j] > arr[j+1]:           # comparision 
            arr[j], arr[j+1]   = arr[j+1], arr[j]   #swap 
        print(" Inner Result: ", arr )
    
    print(" >> Partial Result: ", arr )

print(">>>> Final Result: ", arr )

 

수행 결과 화면

PS D:\PythonCode> python .\BubbleSorting.py
i= 5 j= 0
 Inner Result:  [40, 70, 60, 30, 10, 50]     
i= 5 j= 1
 Inner Result:  [40, 60, 70, 30, 10, 50]     
i= 5 j= 2
 Inner Result:  [40, 60, 30, 70, 10, 50]     
i= 5 j= 3
 Inner Result:  [40, 60, 30, 10, 70, 50]     
i= 5 j= 4
 Inner Result:  [40, 60, 30, 10, 50, 70]
 >> Partial Result:  [40, 60, 30, 10, 50, 70]
i= 4 j= 0
 Inner Result:  [40, 60, 30, 10, 50, 70]
i= 4 j= 1
 Inner Result:  [40, 30, 60, 10, 50, 70]
i= 4 j= 2
 Inner Result:  [40, 30, 10, 60, 50, 70]
i= 4 j= 3
 Inner Result:  [40, 30, 10, 50, 60, 70]
 >> Partial Result:  [40, 30, 10, 50, 60, 70]
i= 3 j= 0
 Inner Result:  [30, 40, 10, 50, 60, 70]
i= 3 j= 1
 Inner Result:  [30, 10, 40, 50, 60, 70]
i= 3 j= 2
 Inner Result:  [30, 10, 40, 50, 60, 70]
 >> Partial Result:  [30, 10, 40, 50, 60, 70]
i= 2 j= 0
 Inner Result:  [10, 30, 40, 50, 60, 70]
i= 2 j= 1
 Inner Result:  [10, 30, 40, 50, 60, 70]
 >> Partial Result:  [10, 30, 40, 50, 60, 70]
i= 1 j= 0
 Inner Result:  [10, 30, 40, 50, 60, 70]
 >> Partial Result:  [10, 30, 40, 50, 60, 70]
>>>> Final Result:  [10, 30, 40, 50, 60, 70]
PS D:\PythonCode>

 

수행결과 분석

 

728x90
반응형
728x90

수행 코드

dataSourceAligned = [15,20,29,30,37, 55, 69, 73, 87, 90]

def my_index( toSearchValue, dataSource ):
    sizeData = len( dataSource )
    low = 0
    high = sizeData-1

    nTrials = 0
    while( low <= high ):
        middle = int((low+high)/2)
        nTrials += 1
        #print(" Trial :" , nTrials, "middle : ", middle )
        if( dataSource[middle] == toSearchValue ):
            #print("탐색 성공 at" , middle, "index" )
            break
        elif( toSearchValue >= dataSource[middle] ):
            low = middle + 1
        else:
            high = middle - 1        

    if( low<= high):
        return middle
    else:
        return -1

toSearchValue = 30
index = my_index( toSearchValue,  dataSourceAligned)
if( index >=0 ):
    print("Found", toSearchValue, "value",  "at", index, "index" )
else:
    print("NOT Found", toSearchValue, "value" )

 

 

수행결과 화면

PS D:\PythonCode> python .\BinarySearch.py
Found 30 value at 3 index
PS D:\PythonCode>
728x90
반응형

+ Recent posts